Major problem with Global variables

0 favourites
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.
  • Good afternoon, I have seen a major problem with Global variables.

    In the middle of developing my game I realized something that has thrown away the work of several months.

    I created a group in my game to put all the variables inside.

    After dragging them all... all the references to those variables in the game code disappeared... and I have not been able to recover the code... because I did not realize it until after several minutes and a backup copy was made too of this change.

    It can't be that simply by moving a variable to a folder all game references will automatically disappear... because it breaks all the game's code.

    This is something that should be fixed immediately... because this can happen to anyone, especially when it is a big game and the number of variables is growing and you want to have the entire game organized so that it is easy to read.

  • For that to happen you would need to delete the global variables. The position of the global variables doesn't matter, no need to put them in a group.

  • No... if a GLOBAL variable is moved to a folder all references are lost automatically... Try it...

  • A folder? Can you share a screenshot?

  • original:

    last:

  • Ah okay you changed it to a local variable, don't move the globals there is no need to organise them or whatever you were trying.

  • There is indeed a need because I have many variables and the best thing is to have them organized... Likewise, when moving it to the folder it turns them into Local and that is not logical...

    If you have more than 500 variables, you'll see if it's necessary to have them organized... that's a Construct3 error, it's the first programming language I've seen that does that and also destroys the functions you already have designed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I say it's a valid complaint. Things shouldn't just silently disappear.

    In Construct 2 it alerted you when moving a variable to a different scope and it caused things to be removed. And moving a global variable to a group does change it's scope.

    However I tested it in Construct 3 r323 and it doesn't alert you. Sounds like a bug to me since it used to notify you in Construct 2. I guess it's always been that way in Construct 3 since I tested as far back as r100 and it still didn't notify you. It's probably just something they overlooked. I think there is a stickied topic on how they prefer to receive bug reports.

  • The problem is OP has said they cannot recover the code but you can. If you move the variable back into the global scope the events return as they were before so nothing is lost.

  • That only happens if you step back from the button... but for that you have to realize at that moment... I still think that a program like Construct3 cannot afford that kind of usability that is out of the ordinary.

  • As lionz stated. Moving a Global Variable into a Group on an Event Sheet, will turn it into a Local Variable. So the Scope of that Variable is only "reachable" within that Group's list of Events/Actions.

    So unfortunately, Global Variables need to be on an Event Sheet outside of Groups. The only way I can think of, to sort of organize global variables. Would be to have one Event Sheet dedicated to only initializing Global Variables. Then, include that Event Sheet on the other Event Sheets.

    I usually do an Initialize Event Sheet, which contains some general global variables, along with Groups/Events for layout initialization. If I have a Global Variable for say Player Health, then I will place that on my Player Event Sheet.

    I do agree that global variables can get out of hand pretty quickly. I do my best to only use them when absolutely necessary. Mostly relying on Instance Variables, and also Local Variables within the Group/Sub-Group that is accessing that variable.

    EDIT: I also agree with, R0J0hound. I completely forgotten that C2 would give a warning notification when moving a global, to a place that would change it's scope. It would definitely be a useful feature to be added back into C3. I've had some mishaps myself from moving variables around.

  • So unfortunately, Global Variables need to be on an Event Sheet outside of Groups. The only way I can think of, to sort of organize global variables. Would be to have one Event Sheet dedicated to only initializing Global Variables. Then, include that Event Sheet on the other Event Sheets.

    I usually do an Initialize Event Sheet, which contains some general global variables, along with Groups/Events for layout initialization. If I have a Global Variable for say Player Health, then I will place that on my Player Event Sheet.

    You can always access a global variable, even if it is not on any included/referenced event sheet. In fact you don't even need to "initialize" the variables at all, they can be on a unreferenced sheet. You can see them as "hoisted"..

    Furthermore global variables can only be on the top level, and not in any other scope, since then they would obviously not be "global" any longer. If you need a variable inside a group (or event) it will be a local variable.

  • > So unfortunately, Global Variables need to be on an Event Sheet outside of Groups. The only way I can think of, to sort of organize global variables. Would be to have one Event Sheet dedicated to only initializing Global Variables. Then, include that Event Sheet on the other Event Sheets.

    >

    > I usually do an Initialize Event Sheet, which contains some general global variables, along with Groups/Events for layout initialization. If I have a Global Variable for say Player Health, then I will place that on my Player Event Sheet.

    You can always access a global variable, even if it is not on any included event sheet. In fact you don't even need t "initialize" them at all, they can be on a un referenced sheet. You can see them as "hoisted"..

    Furthermore global variables can only be on the top level, and not in any other scope, since then they would obviously not be "global" any longer. If you need a variable inside a group it will be a local variable.

    Good to know. Maybe my explanation of your second paragraph seemed off, but that was what I was trying to say. My wording is often off of what I'm thinking conceptually. ADHD, and mind to mouth/word, does not work out for me often XD

    The first paragraph goes further though. So basically, the idea of having all global vars on a single event sheet. But, then that event sheet does not need to be "included" on other sheets.

    EDIT: Everyone finds there own way of organizing. For me, I try keep Global Variables on an Event Sheet that makes sense to me. Such as the Player Health, being at the top of an event sheet named "Player".

    Again. Only using Global vars if absolutely necessary. It's better to use Instance/Local variables whenever possible, in my opinion. Then set them accordingly, and re-initialize them back to their original state when necessary, etc.

  • There is indeed a need because I have many variables and the best thing is to have them organized... Likewise, when moving it to the folder it turns them into Local and that is not logical...

    If you have more than 500 variables, you'll see if it's necessary to have them organized... that's a Construct3 error, it's the first programming language I've seen that does that and also destroys the functions you already have designed.

    Try move a variable in javascript into a lower scope and see if you can access it within the top level again, you wont. :)

    I think you should try another approach than having 500 global variables for storing boolean data. Or if this is the approach you want to use just have one dedicated sheet with variables only.

  • That only happens if you step back from the button...

    Not necessarily, you can still move your now-local variable back to global scope - actions and conditions will reappear without having to Undo other changes (only if you are on the same session and didn't save-load the project since the change). Pretty nice feature, but having a warning would be useful anyway.

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