Notifications
Clear all

[Closed] Dynamic Rollout Accessing Functions

I could have swore I ran a gc(), but either I didn’t or it didn’t clear out the globals.

SHRUGS
-Eric

Could someone explain to me how it is out of scope please?

If I create a normal rollout, one that isn’t dynamic and then try to run the function without it being inside a global struct, it can access it properly.

However, if it is dynamically generated, it cannot “see” the function.

To illustrate my point, here is a piece of code where the non-dynamically created rollout can access the function whilst the dynamic rollout cannot


  (
  	  local message = "print this message"
    
  	  function printMessage =
  	(
  		format "%
" message
  	)
    
   
  	  local rollStream = stringStream ""
    
  	  format "rollout rlt \"Rollout\"
" to:rollStream
  	  format "(
" to:rollStream
  	  format "button btn1 \"Print Message\"
" to:rollStream
  	  format "on btn1 pressed do
" to:rollStream
  	  format "(
" to:rollStream
  	  format "printMessage()
" to:rollStream
  	  format ")
" to:rollStream
  	  format ")
" to:rollStream
    
  	  createDialog (execute (rollStream as string))
  	
  	rollout testRollout "Test Rollout"
  	(
  		button btn2 "Print Message
" 
  		
  		on btn2 pressed do
  		(
  			printMessage()
  		)
  	)
  	
  	createDialog testRollout
    )
  

From the above, testRollout has no problems whilst rlt does.

Thanks

 JHN

From the helpfile:

The scope of variables used in the evaluated string is global and not the scope in effect when the execute() method is executed.

Lookup execute() in the manual, it has more info on this as well. So again if you declare the function and the message global it would work for both rollouts. Hence my suggestion for a global struct with your functions… you can access it from any scope then.

-Johan

Thanks again JHN!

Page 2 / 2