put string into multiple variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
put string into multiple variables
this might sound silly but i want to put 0 into about 20 different variables and dont want to have to write "put 0 into var1" then another line "put 0 into var2". Id rather say something like "put 0 into va1 and var2 and var3 and so on" this will be a lot easier
Re: put string into multiple variables
Hi Da_Elf,
just DO it, you lazyboy:
Best
Klaus
just DO it, you lazyboy:
Code: Select all
...
repeat with i = 1 to 20
do ("put" && 0 && "into tVar" & i)
end repeat
...

Best
Klaus
Re: put string into multiple variables
Thanks Klaus. I have to look into this "do" command. So there would be no other way of doing it? i used var1, var2, var3 as examples. What if i wanted to put 0 into "TotalSales" , "TotalSavings" , "SubTotal" , "TotalTaxes". etc etc.
wait i think i have it
wait i think i have it
Code: Select all
put "TotalSales,TotalSavings,Subtotal,TotalTaxes,etc,etc" into vars
set itemDelimiter to comma
repeat for each item myVar in vars
do ("put" && 0 && "into " & myVar)
end repeat
Re: put string into multiple variables
EX-ACTLY! 

Re: put string into multiple variables
thank you so much. You have been a help to all of us novices. i might even be able to clean up some of the code ive already done by using the "do" option. (why did i think programming a POS would be simple lol)
Re: put string into multiple variables
Maybe another option could be an ARRAY?
No need to DO anything there:
Only ONE variable, worth a thought 
No need to DO anything there:
Code: Select all
...
put empty into tArray
put "TotalSales,TotalSavings,Subtotal,TotalTaxes,etc,etc" into vars
repeat for each item myVar in vars
put 0 into tArray[myVar]
end repeat
...

Re: put string into multiple variables
hello,
i want to do something similar: if mutliple variables are set to true, then...
i tried this:
or if g1True,g2True,g3True is true, then.. but nothing. thats a pretty old thread, so if someone sees it.. can you help me? thank you! 
i want to do something similar: if mutliple variables are set to true, then...
i tried this:
Code: Select all
if _g1True is true and _g2True is true and _g3True is true
then
answer "working"
end if

Re: put string into multiple variables
Hi kelyanok,
just made a little test and it works as advertized!
Hint: When checking a Boolean value for TRUE, you can omit the = TRUE part.
If we do, the engine thinks we mean TRUE, so this works, too:
Best
Klaus
just made a little test and it works as advertized!
Code: Select all
on mouseUp
put TRUE into _g1True
put TRUE into _g2True
put TRUE into _g3True
if _g1True = true and _g2True = true and _g3True = true then
answer "working"
end if
end mouseUp
If we do, the engine thinks we mean TRUE, so this works, too:
Code: Select all
on mouseUp
put TRUE into _g1True
put TRUE into _g2True
put TRUE into _g3True
if _g1True and _g2True and _g3True then
answer "working"
end if
end mouseUp
Klaus
Re: put string into multiple variables
What Klaus said !Klaus wrote: Maybe another option could be an ARRAY?
No need to DO anything there:
Only ONE variable, worth a thought![]()
but even an easier way to build your array out of list:
Code: Select all
local mySuperArray = "TotalSales,TotalSavings,Subtotal,TotalTaxes,etc,etc"
split mySuperArray with comma as set
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: put string into multiple variables
hello Klaus!
thank you for your response!
i tried to use your code, but it didnt work!
so what i did first is put some code when the button "start" is pressed:
to be sure that the probleme wasnt there: it is not. so ive made another variable to check if my code above wasnt working or something like that, still no. i checked if everytime the player succeed, you put TRUE into _gxTrue, i put "global _gxTrue" everywhere ect ect.. but STILL NO!!
can you help me pleaaase thank you very much.
i can maybe send you my app, say me if you want to.
Ps: by _gxTrue, i mean i put _g1True, _g2True and _g3True.
thank you for your response!
i tried to use your code, but it didnt work!

so what i did first is put some code when the button "start" is pressed:
Code: Select all
on mouseUp
put FALSE into _g1True
put FALSE into _g2True
put FALSE into _g3True


can you help me pleaaase thank you very much.
i can maybe send you my app, say me if you want to.
Ps: by _gxTrue, i mean i put _g1True, _g2True and _g3True.
Re: put string into multiple variables
Hm, are these GLOBAL variables? If yes, do you declare them in every script you use them?
I think this is different than in other programming languages.
Like this:
I think this is different than in other programming languages.
Like this:
Code: Select all
global myGlobalVar
on mouseup
## do this and that with myGlobalVar
end mouseup
command my_custom_command
## do somethong else with myGlobalVar
end my_custom_command
Re: put string into multiple variables
hello Klaus
well i did put global _gxTrue on every box yes.
still didnt found why. is there a way to send you my code?
thanks
kelyan
well i did put global _gxTrue on every box yes.
still didnt found why. is there a way to send you my code?
thanks
kelyan
Re: put string into multiple variables
Hi kelyan,
OK, send the stack to klaus AT major-k.de with a short info, where to look.
Or put it online somewhere and send me the link.
Best
Klaus
OK, send the stack to klaus AT major-k.de with a short info, where to look.
Or put it online somewhere and send me the link.
Best
Klaus