Expanding multiple vars in a single string var?

Super new to game dev here!

I'm trying to expand multiple variables within a while loop and it seems like it should be doable, but it's only "half" working for me.

I'm iterating thru a loop 3 times to swap a tile based on a number stored in 3 different vars, using i in each iteration to get the value of each var.

I'm expecting swap "time{mCode{i}DispInit}" to resolve to time0, time1, thru time9, but what I'm getting is timemCode1DispInit}, which crashes the game because it's an invalid tile name.

It's resolving the inner curly braces, but I don't understand why it's escaping the left outer curly brace, but leaving the right outer curly brace in the string literal.

Hope this makes sense, thanks to all in advance for the help! - Casey

i = 1
xDefault = 4
yDefault = 7
while i<=3 do
	tell xDefault,yDefault to
		log "time{mCode{i}DispInit}"
		swap "time{mCode{i}DispInit}"
		xDefault += 8

(I took the liberty of fixing your code formatting for legibility.)

Sorry, let me see if I understand what you're trying to do:

  • You have tiles named time0 through time9
  • You need to loop over these tile names and do something with each one

What's the purpose of DispInit? Is that part of the tile name?

I have found that with Pulp you can only embed a single set of braces { }. You can't nest them within each other as you are doing { { } }, it will only parse one of them.
You could do them in a series though, in separate lines/variables.

Yo thanks for the reply!! This may be the trick. Format it once with one var, then format again with the 2nd?

Yep. Will be more work, more lines, but I treat it like math operators in Pulp. One on each line :smiley:

@dwineman thanks so much for the reply! Thanks for formatting that for me, I was having trouble getting the formatting the way you did.

mCode1DispInit, mCode2DispInit, mCode3DispInit are holding values (0-9) that I'm using to determine 'time0,1,2,etc'. I'm using the while loop to swap a different tile representing each of the 3 DispInit values.

Will @Jongjungbu's solution achieve that? I've tried testing it, but still not getting the results that I want.

This really helps. very much appreciated!

Yes, unfortunately Pulp's parser isn't sophisticated enough to expand strings recursively (that is, expand the result of an expansion). Doing it in steps should work though.

value = "mCode{i}DispInit"
tilename = "time{value}"
swap tilename
1 Like