Page 1 of 1
put string into multiple variables
Posted: Thu Nov 12, 2015 12:40 pm
by Da_Elf
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
Posted: Thu Nov 12, 2015 1:51 pm
by Klaus
Hi Da_Elf,
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
Posted: Thu Nov 12, 2015 2:56 pm
by Da_Elf
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
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
Posted: Thu Nov 12, 2015 3:44 pm
by Klaus
EX-ACTLY!

Re: put string into multiple variables
Posted: Thu Nov 12, 2015 3:55 pm
by Da_Elf
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
Posted: Thu Nov 12, 2015 4:16 pm
by Klaus
Maybe another option could be an ARRAY?
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
...
Only ONE variable, worth a thought

Re: put string into multiple variables
Posted: Sat Mar 28, 2020 6:54 pm
by kelyanok
hello,
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
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!

Re: put string into multiple variables
Posted: Sat Mar 28, 2020 10:45 pm
by Klaus
Hi kelyanok,
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
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:
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
Best
Klaus
Re: put string into multiple variables
Posted: Sun Mar 29, 2020 9:06 am
by Thierry
Klaus wrote:
Maybe another option could be an ARRAY?
No need to DO anything there:
Only ONE variable, worth a thought
What Klaus said !
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
Take care,
Thierry
Re: put string into multiple variables
Posted: Sun Mar 29, 2020 8:38 pm
by kelyanok
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:
Code: Select all
on mouseUp
put FALSE into _g1True
put FALSE into _g2True
put FALSE into _g3True
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.
Re: put string into multiple variables
Posted: Sun Mar 29, 2020 9:17 pm
by Klaus
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:
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
Posted: Mon Mar 30, 2020 11:28 am
by kelyanok
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
Re: put string into multiple variables
Posted: Mon Mar 30, 2020 11:49 am
by Klaus
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