Page 1 of 1

Dynamic variable creation

Posted: Mon Apr 11, 2016 11:52 am
by Jordy
Just a general question is LiveCode capable of creating global variables on the fly.

Simple example
A game you have turns, as players take turns you add 1 to a global gTurnNumber

Could you get gTurnNumber and get LC to create a new global while program running that gTurnWinner1, gTurnWinner2,
gTurnWinner3 that are created as game progresses?

Re: Dynamic variable creation

Posted: Mon Apr 11, 2016 12:00 pm
by Klaus
Hi Jordy,

this is possible, but not really straightforward and probably not worth the effort!
Use a (global) ARRAY instead:
...
## Then you can do something like this:
add 1 to myGlobalGameArray["player1"]["turn"]
...
Get the picture?


Best

Klaus

Re: Dynamic variable creation

Posted: Mon Apr 11, 2016 3:47 pm
by dunbarx
I have so much fun.

What Klaus means is that you would have to take a few minutes and examine the following handler in a button:

Code: Select all

on mouseUp
   repeat with y = 1 to 3
      do "put" && y && "into newGlobal" & y
      put newGlobal & y & comma after header
   end repeat
 
   put "global" && header into globalHeader
   
   set the newGlobalScript of  me to globalHeader & return & return & the script of me
   answer the newGlobalScript of  me 
end mouseUp
LC can, er, "do" anything, but what I just did is old-fashioned.

Craig Newman