How do I edit a global variable from within a function?

0 favourites
  • 7 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Is it possible to edit a variable from inside a function?

    I haven't had any luck testing this out. I just had a simple function that needs to change and external variable. I am guessing this isn't in the scope of a function.

    Thank you very much in advance.

  • You can but to be safe it's better to use a variable inside the function because global variables can change and might alter while the function is running or something like this. You can try it for now but you may come across some bugs in a bigger game.

    If the global variable didn't change when you tested it then you must not be calling the function or something else is changing the global variable so it looks like it is unchanged (already the kind of bug I was referring to).

  • I do it all the time in C2. It should work fine unless something changed in C3. I can’t find any info of such a change.

    I don’t agree with the lack of safety though. Things are run in order and the global will only change when you tell it to.

  • Are you sure the variable is global?

    Are you sure the variable isn't set to constant?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Of course you can set a global variable inside a function. The whole purpose of global variables is you can access them anywhere. If you don't see it, it's probably not a global variable, or is set to be constant.

  • Thanks for the replies everyone. My code was getting gross and messy and I just rewrote it better. I must have had it set to static? I also need to learn more elegant ways of using Construct. :) I am still bashing around until things work. hahaha

    cheers.

  • If it's in a group or a sub-event it will say local instead of global. Making it static will make it behave like a global.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)