Notifications
Clear all

[Closed] Accessing elements from different rollouts

I can’t wrap my head around this one. Here’s an example of what I mean, I’ve included the code. Let’s say I wanted to access the value of the spinner from the 2nd rollout from the first one. I know you can access it by going

subRollout02.testSP.value

but this won’t work when using a macro. Am i missing something?

 
[size=3]rollout[/size] mainRoll "Main Rollout" height: 150
 
(
 
	subRollout sub01 height: 70
 
	subRollout sub02 height: 70
 
)
 
rollout subRoll01 "Sub rollout 01"
 
(
 
	button testBUT "Print Value"
 

 
	on testBUT pressed do
 
(
 
	print testSP.value
 
)
 
)
 
 
 
rollout subRoll02 "Sub rollout 02"
 
(
 
	spinner testSP "Spinner" range:[0,100,50]
 
)
 
 
 
createDialog mainRoll
 
addSubRollout mainRoll.sub01 subRoll01
 
addSubRollout mainRoll.sub02 subRoll02


4 Replies

You need to define the rollout you want to access as a global variables.


macroscript someTestRollouts category:"Your Tools" buttonText:"Test Rollouts"
(
   global mainRoll
   global subRoll01
   global subRoll02
 
   rollout mainRoll "Main Rollout" height: 150
   (
	  subRollout sub01 height: 70
	  subRollout sub02 height: 70
   )
   
   rollout subRoll01 "Sub rollout 01"
   (
	  button testBUT "Print Value"
   
	  on testBUT pressed do
	  (
		 print subRoll02.testSP.value
	  )
   )
 
   rollout subRoll02 "Sub rollout 02"
   (
	spinner testSP "Spinner" range:[0,100,50]
   )
   createDialog mainRoll
   addSubRollout mainRoll.sub01 subRoll01
   addSubRollout mainRoll.sub02 subRoll02
)

Thank you, Stev. That’s a good solution.

It will also work if you declare them as locals. This is probably a matter of personal preference, but in my experience it’s better to use locals unless there’s no way around using globals.

Cheers,
Martijn

Ah, so it does. I agree, avoiding to pollute global space can help in the long run.