Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

rollout vs functon scope -- function is losing....

rollout vs functon scope -- function is losing....

Anonymous
Not applicable
381 Views
3 Replies
Message 1 of 4

rollout vs functon scope -- function is losing....

Anonymous
Not applicable
so I have the following error, which I cannot explain.

---------------- faux code follows ----

rollout: rollout1 "rollout 1" pos:blah blah blah
(
button: blah blah

global function1
fn function1 =
(
blah blah blah
)

) -- end rollout1

rollout: rollout2 "rollout 2" pos:blah blah blah
(
button: blah blah

global function2
fn function2 =
(
function1()
)

) -- end rollout2

------------------- end faux code --------------------------


NOW, why does function2 report that function1 is not defined? It cannot see function1's definition????? "Call needs function or Class, got: undefined"

TiA

MB
0 Likes
382 Views
3 Replies
Replies (3)
Message 2 of 4

paulneale
Advisor
Advisor
try...

rollout1.function1()

Mighty_Marcos wrote:
> so I have the following error, which I cannot explain.
>
> ---------------- faux code follows ----
>
> rollout: rollout1 "rollout 1" pos:blah blah blah
> (
> button: blah blah
>
> global function1
> fn function1 =
> (
> blah blah blah
> )
>
> ) -- end rollout1
>
> rollout: rollout2 "rollout 2" pos:blah blah blah
> (
> button: blah blah
>
> global function2
> fn function2 =
> (
> function1()
> )
>
> ) -- end rollout2
>
> ------------------- end faux code --------------------------
>
>
> NOW, why does function2 report that function1 is not defined? It cannot see function1's definition????? "Call needs function or Class, got: undefined"
>
> TiA
>
> MB
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 3 of 4

Anonymous
Not applicable
It might not be obvious, but according to the "Rollout Clauses" topic in the Help, functions defined inside a rollout are ALWAYS local to that rollout, just like the FOR loop variable is always local to the loop even if you have pre-declared it as global before the loop.

So you declaring function1 as global inside the rollout has NO effect on the Function definition which does never check the global scope to see if that variable already exists and simply creates a local one implicitly. Thus, you end up with a global variable function1 containing undefined and a local variable function1 containing the function.

If you would say

global functtion1 = 42

and run your code, checking the content of function1 after the rollout has been evaluated will show you there is a global variable function1 still containing 42, and a rollout1.function1 local variable inside the scope of the rollout containing the function.

If you do want a global function, declare it OUTSIDE of the rollout.
0 Likes
Message 4 of 4

Anonymous
Not applicable
Thank you both for your replies, was away from the office for a few days so I apologize for the lateness of my reply.

Paul, thank you for your reply, that did it, adding the rollout's name to the function call fixed it!

Bobo, I did not declare the functions globally since they write data to the some of the listboxes in the rollout. And some of the buttons I have in that rollout refer to these functions as well.

Basically i needed rollout2 to cause a refresh of rollout1, the rollout1 function was defined within rollout1's def since other buttons or operations in rollout1 also call this refresh. But just making it rollout1.function() worked great.

Thank you both!

MB
0 Likes