Big Problem with string concatenation - it's nonexistent

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 9341
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Big Problem with string concatenation - it's nonexistent

Post by Tdarcos »

Consider the following piece of code:

Code: Select all

routine DMFB
{
local describe, describe2

   print "Original values "; 
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   Describe  = "One"
   Describe2 = "Two"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   Describe = Describe + describe2
   print "Final result:"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   print "Sample ends."
You get the following result when this routine is called:

Original values describe = '' describe2 = ''
describe = 'One' describe2 = 'Two'
Final result:
describe = '' describe2 = 'Two'
Sample ends.

Clearly, the compiler doesn't support concatenations. Typical practice is the + sign for this purpose; the manual doesn't even contain the word "catenate" or mention any capability to combine two strings. At least I know this now so I can work around it.
"I really feel that I'm losin' my best friend
I can't believe this could be the end."
- No Doubt, Don't Speak

Roody_Yogurt
Posts: 2181
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

Nope, you're right, that isn't possible. You can "add" strings, though, by using the "text to" and "dict" commands.

Code: Select all

! add this first line to the beginning of the source file
$MAXDICTEXTEND = 7
! sets aside some space so we can add more words to the dictionary table after compilation

array describearray[7] ! a seven element array can hold six letters

routine DMFB
{
local describe, describe2

   print "Original values: ";
   print " describe = '"; describe;"' describe2 = '"; describe2;"'"
   Describe  = "One"
   Describe2 = "Two"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
	text to describearray
	print Describe;
	print describe2;
	text to 0
	Describe = dict(describearray, 7)
 
   print "Final result: ";
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   print "Sample ends." 
}

Also, you wouldn't have to use dict if you weren't actually setting the describe variable to the combined string. You could just fake it, of course:

Code: Select all

!...
	text to 0
   print "Final result: ";
   print " describe = '"; StringPrint(describearray);"' describe2 = '"; describe2;"' "
!...

Post Reply