Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Is it possible to build a string from substrings?

A topic by Garry Francis created Jun 18, 2020 Views: 117 Replies: 6
Viewing posts 1 to 2
Submitted

Consider the following fragment of code:

: append "It's a wooden door that is currently ";
: if (is_door_open) {
   : append "open.";
}
: else {
  : append "closed.";
}
: if (is_lock_broken) {
   : append " The lock is broken.";
}
: print "";

Is it possible to do something like this, except building up a string, rather than printing directly to screen?

Host

Yes, you can just use "+" between two strings in the expression syntax.

You can set the result to a string or you can append directly inside a print.

You can also append in a dynamic string reference too (not demonstrated below).

start_at = start
locations { start; }
strings   { tmp : string ; }
integers  { seven : integer "7" ; two : integer "2" ; } on_startup {    : print {("This " + "is " + "a " + "built " + "string ("+(seven+two)+")." )}
   
   : press_any_key ;
   
   : set_string var = "tmp"  {( "This " + "is " + "a " + "built " + "string ("+(seven*two)+")." )}
   : print "{tmp}" ;
   
   : press_any_key ;
}
Submitted (1 edit)

I realise that, but I don't want to do it all in one step. I want to do a test, then add something to the string, then do another test and add something to the string and so on.

Host

Use the old value of the string in the set string.

E.g.

: set_string var="tmp" {(tmp + " append text")}
Submitted

Oh, I can do that? That's perfect. Thanks.

Submitted

It turns out that I can use:

: set_string var = "name" text = "string";
: set_string var = "name" {("string")}

But I can't use:

: set_string var = "name" "string";
: set_string var = "name" text = {("string")}

I had tried using the last form and that's why it wasn't working.

Host

I updated the document to show a second example of this (there was already one in there), but I made the second example more obvious.

https://adventuron.io/documentation/#QuickStartStringExpressions