Loop controled by multiple variables

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2009   #1
Loop controled by multiple variables

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
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #2
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
 
Old 02 February 2009   #3
Thanks! Testing it
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #4
Great! i think that is what i needed

Now to work on the implementation of my current script

THANKS AGAIN!!
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #5
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:11 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.