[Closed] global variable call
I have a code where I have 2rc menu’s and then a rollout. I declare the rollout globally before the rollout.
so the order goes
rcmenu
rcmenu
–global decloration of rollout
rollout
In the rcmenu code i call the rollout by its global call to get to its combobox
Library.pallete.items.
On other people’s computer it gets an error message saying that “pallete” is undefined.
But on mine it works.
Could it be that i’m not declaring my rollout as global at the top of my script, or could it possibly be something else?
Thanks.
The global declaration of the rollout should be BEFORE the two RC menus if the menus are supposed to “see” the rollout.
If you run the script twice, it will probably start working on any machine, but the trick is to make it run the first time correctly…
Perhaps slightly off topic, but a method I always find useful is putting all the UI things in a struct, so that you can use just one global for all UI elements:
struct myUI (
rcmenu firstRC (
--code here
)
rcmenu secondRC (
--code here
)
)
global myUI = myUI();
With that done, you can call anything inside the structure by using:
myUI.firstRC
--or:
myUI.secondRC
global rlt_main
rcmenu1 (
// access rollouts with rlt_name.rlt_element like
// rlt_main.btn_Press.width = 200
)
rcmenu2 (
)
rlt_main (
button btn_Press “Press me”
)
In the above example there is no need for a structure and you accomplish the same thing.
True, for a just one or two things that you want to be global it’s more simple indeed. For more complex things a structure might be easier, as you can access everything within the structure globally, with just one global variable.
Thanks for clearing that up for me . The struct idea seems like a good thing to implement as well, hadn’t thought of that.