Handling Strings

Sorry for coming up with a simple topic again, but the habit of I6 to break everything down into object numbers is driving me nuts. I simply want to print a string with a variable middle part. Like, in the logic of pretty much every other programming language,
x=“There is a “;
if(colour==1) x=x+“red”;
if(colour==2) x=x+“blue”;
x=x+” balloon.”;
How is that done in Inform 6? “Programming error: tried to print (string) on something not a string” was the nicest game message I was able to achieve, “Programming error: (object number -7428) has no property print to send message” was the most sophisticated one.

You should simply print everything sequentially.

print "There is a ";
if (colour == 1) print "red";
else if (colour == 2) print "blue";
print " balloon.";

If you really want to manipulate strings, it’s not really trivial with Inform 6: you have to change the output stream to an array, print something so that each character of the text goes into that array and then do what you want to do with them. But when just printing, it’s overkill.

(With Inform strings, characters are not necessarily stored directly in memory, so strings are just represented as their address in the memory.)

Weird, the forum exploded for a few minutes there and it lost my reply.

The I6 way is just to print each piece individually. String concatenation isn’t really a thing in Inform; while it’s not impossible, if you’re trying to do it then it’s probably not the correct approach.

It was that simple.


. o O ( Inform 6… )

The same happened to me, but as this problem happened to me several times on other forums in the past, I now have the habit to copy my reply into the clipboard before hitting “send”.

That’s why I was so quick to reply after the forum came back online.

Sorry, the forum was briefly down for a software update. Doesn’t happen very often.

1 Like