PDA

View Full Version : initialize variable



chriss
September 23rd, 2009, 06:14 AM
hi all

how can i initialze a variable just once and not always the script is triggered?? i want to set a variable only if it is nil (so on startup) but not allways if the script is triggered.

thx and greetz

chriss

quixote
September 23rd, 2009, 11:06 AM
x = x or 0


If the variable x exists then it will equal itself, otherwise will be set to 0. The digit 0 can be anything; you can replace that with a string in quotes as well.

kwaugh
September 23rd, 2009, 02:09 PM
I didn't know that - glad I read all the new posts each day...

chriss
September 24th, 2009, 12:49 AM
big thx for that

greetz

chriss

Ron
September 25th, 2009, 03:56 PM
For a more readable version:



if not x then
x = 0
end


will do the same.