[Solved] How do I use a global or object variable as a mouse jointId?

When adding a mouse joint to an object, there is the option variable to store the joint id. However, this seems to only take a scene variable. Is it possible to use a global or an object variable instead?

Or do I have to create a joint id variable for each scene? Which is a bit of a pain if the game has a hundred scenes as levels.

Not sure what is joint ID, but you definitely don’t have to create a hundred variables for a hundred levels.
You can use Structure Variables and/or Functions, and then maybe Storage if you want to save them later.
Structure variable (to specify variable name and value dynamically):

Storage function (to save variables into computer):

Feel free to elaborate your questions if needed, with screenshots of project if possible.

The Joint Id is an optional parameter at the end of the ad joint section (as per first screen shot).The drop down for this parameter only offers scene variables.


And the pop-out icon only gives access to the scene variable edit screen:

You can use a proxy variable for hack.
I mean you can use a scene variable in this action, and at you can add another action for copy the value of the scene variable into a global variable.
And if you use scene variable structure you can copy whole structure to the global variable no need X event for copy the variables, just one :slight_smile:

I don’t know why it’s limited at scene variable, maybe we can extend this, i’ll take a look.

Can you test to write the name of your global variable instead use scene selector?

I tested it out and removed my scene variable and added a global variable with the same name.

And it worked! So I guess it looks for a scene variable of that name first, and if it can’t find it, searches the global variables.

Thanks @Bouh for the suggestion. It’s made the game development a little bit simpler :slight_smile:

Not sure about that, in backend the engine create and initialize the variable with the value given if this variable isn’t used before.
Check with the debugger where live your variable.

Yes, you’re right . The actions still referred to the scene variable. When I changed this to the global variable, it stopped working.:frowning:

On the bright side, I guess I don’t have to declare the variable for each scene. :slight_smile: