Usually, when I make games, I use tables for everything. In pulp, that's not supported. I could work around this if I could dynamically create variables. Is this possible somehow?
Pseudocode of what I'd like to achieve:
While x < 20 do
x++
var{x} = 1
End
Anyone found a way to do something like this?
orkn
(Scott)
September 4, 2022, 5:19pm
2
Unfortunately this is one of Pulpscript's limitations!
You can't dynamically create any arbitrarily named variable, but you can make use of events to get partway there.
Provided you know all of the potential variable names upfront you can create "setter" event handlers. For example:
on set_var1 do
var1 = i
end
on set_var2 do
var2 = i
end
on set_var2 do
var2 = i
end
// ...and so on
Then to modify your pseudocode, you could do:
i = 1
while x < 20 do
x++
call "set_var{x}"
end
This works because events are called with a string, so you can use string formatting to dynamically call the right event
I guess I can make that work. I'll have to rethink some systems, but that's fine. Thanks!