PDA

View Full Version : Loop controled by multiple variables


CerberusC
02-27-2009, 11:24 PM
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

magicm
02-27-2009, 11:38 PM
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 "% + % = %\n" val_a val_b (val_a + val_b)
)
)
Hope this helps,
Martijn

CerberusC
02-28-2009, 12:00 AM
Thanks! Testing it :)

CerberusC
02-28-2009, 12:02 AM
Great! i think that is what i needed :)

Now to work on the implementation of my current script :)

THANKS AGAIN!!

CGTalk Moderation
02-28-2009, 12:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.