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}"
i++
xDefault += 8
end
end
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.
@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.
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