Creating a variable inside of a rollout

Hey folks, I'm working on a small script and running into an annoying problem. Essentially when the user clicks a button, on the "pressed do" part of the roll out I want to create a variable, (such as "variableName = spinnerUserChanges.value") to then use multiple times during the next few lines (rather than constantly having to write "(spinnerUserChanges.value)".

But when I do this and try to run it constantly faults at that line.

I don't understand why this happens... is there a specific way you have to define variables while working with roll outs?

Much thanks!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mackinder's picture

Actually, scratch that, it

Actually, scratch that, it was because I wasn't setting brackets around the code... I had just one line of code so it worked fine, the second line then messed it up.

That always trips me up, silly mistake.

Thank you again.

Mackinder's picture

Ah! I understand now that I

Ah! I understand now that I wasn't declaring it as either local or global... although I don't understand why I need to for a roll-out... to be honest I don't grasp why or when locals and globals need to be set.

Thank you though, you've saved me from a serious headache.

Anubis's picture

should not been a problem

Variant 1: store the value as local visible to
the whole rollout using spinner-handle:

rollout ro1 "..."
(
	local spVal = 0
 
	spinner s1 "" range:[-100,100,0]
	button b1 "..."
 
	on s1 changed val do (spVal = s1.value)
 
	on b1 pressed do (print spVal)
)

or Variant 2: make it visible to the button only:

rollout ro1 "..."
(
	spinner s1 "" range:[-100,100,0]
	button b1 "..."
 
	on b1 pressed do
	(
		local spVal = 0
		print spVal
	)
)

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.