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.

loading a global variable first

loading a global variable first

mark_aldred
Advocate Advocate
538 Views
4 Replies
Message 1 of 5

loading a global variable first

mark_aldred
Advocate
Advocate

I have a bunch of objects with FloatScript controllers. One of the scripts contains a global variable that the others reference. When I open the file, it looks like two of the objects are loaded before the one containing the variable, so I get two errors.

 

1. How do I ensure the global variable is loaded first?

2. I'd like access to the global variable in the UI so I can change it regularly. What's the best way to do this and still have it load first?

0 Likes
539 Views
4 Replies
Replies (4)
Message 2 of 5

MartinBeh
Advisor
Advisor
What type/value does the global variable hold?

The best would probably be to use a custom attribute (attached to the screen root; or attached to some helper object in your scene) to hold your global value. That way, the value always is available, is saved/loaded with the scene, and your GUI could also find it. Unfortunately, CAs are a bit more cumbersome to use in MAXScript.

One could also use a Custom Scene File Property to hold the value.

An even more hacky way might be to define it in a startup MAXScript file (yourname.ms in the plug-in path)
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 3 of 5

mark_aldred
Advocate
Advocate

Thanks. It's just a simple float variable.

 

In the end I put it in a script controller in a different object, and for some reason that ensured that the variable was loaded first. Maybe because the object is closer to the origin? Object creation order? I don't know. 

 

 

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor

@mark_aldred wrote:

...

1. How do I ensure the global variable is loaded first?

2. I'd like access to the global variable in the UI so I can change it regularly. What's the best way to do this and still have it load first?


1. Global variable is a bad solution to use with script controllers.
2. Using a CA is also not a good solution if this CA is not an element of your framework (part of your plugins and tools)

 

One solution might be to use a constant added to the script controller. But I need a little more information about the role of this #global in order to offer a better solution.

0 Likes
Message 5 of 5

denisT.MaxDoctor
Advisor
Advisor
One way or another, any use of an #external to the controller (not defined with the controller) variable in the script controller is linked with the problem of data loading order. If such a use is necessary (which one might assume), you have to add to the controller script a check for the existence and a correct definition of such a variable ...
0 Likes