Notifications
Clear all
[Closed] Loop controled by multiple variables
Feb 28, 2009 12:24 am
Hi all.
I want to do a loop that is controlled by multiple variables, Example:
rollout vari "variable test" width:150 height:400
(
spinner var_a "Variable A" range:[0,10,0] type:#integer pos:[60,10] width:60
spinner var_b "Variable B" range:[0,10,0] type:#integer pos:[60,30] width:60
button tess "Test" pos:[5,50] width:100
on var_a changed val do (
print var_a.value as String
)
on var_b changed val do (
print var_b.value as String
)
on tess pressed do (
)
)
varfloater = newRolloutFloater "Variable Test" 150 120
addRollout vari varfloater
I want that when i press the button i can saw the result of the addition of the two values of the spinners until i arrive to the maximun values of the two spinners, then print a message
I mean if i have in an spinner a value of 2 and in the other a value of 3 the results in the output must be:
0+0 =0
1+1 =2
2+2 =4
2+3 =5
and then the printed message: “we have arrived”
0
2
4
5
"we have arrived"
Thanks
3 Replies
Feb 28, 2009 12:24 am
The amin and amax functions are ideal for these kinds of things. Here’s an example:
on tess pressed do
(
-- get the highest value of both spinners
-- this will be the end point of our loop
local loopEnd = amax var_a.value var_b.value
for i = 0 to loopEnd do
(
-- get the value for both spinners. the amin function
-- makes sure the result does not exceed the spinner's value
local val_a = amin i var_a.value
local val_b = amin i var_b.value
-- print the result
format "% + % = %
" val_a val_b (val_a + val_b)
)
)
Hope this helps,
Martijn
Feb 28, 2009 12:24 am
Great! i think that is what i needed
Now to work on the implementation of my current script
THANKS AGAIN!!