Use multiple global variables with the same name

0 favourites
  • 13 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.
  • Hi!

    I want to know if it is possible to use mulitple global variables with the same name in different event sheets.

    I got a game with different levels.

    Seperated in:

    Level 1 = EventsheetLevel1

    Level 2 = EventsheetLevel2

    etc..

    I want to use global variables in both event sheets with the same name but i can not make duplicates.

    Can any one tell me how i am able to do this?

    One way i can think of is including all global variables in one sheet, and in the different sheets set the global variables.

    So it would be:

    EventsheetLevel1

    SET GLOBALVARIABLE1 1 = ....

    EventsheetLevel2

    SET GLOBALVARIABLE1 34 = ....

    That way it is possible but the way to edit it is way more time taking than just normal global variables.

    Thanks in advance!

  • A global variable is global and as such can be used in your whole project. If you'd like the variable to have different values in different levels you will have to set these values in the event sheet.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I do not know what you mean for sure.

    What i got now is eventsheets like:

    Eventsheetlvl1

    Eventsheetlvl2

    And on the layout i do it like:

    if level = 1 include Eventsheetlvl1

    if level = 2 include Eventsheetlvl2

    Thats works great, but i can not use duplicates of global variables.

  • There is no need for duplicates, for the variables are global.

    On start of layout - set global variable

  • Hi,

    Yeah i was afraid so. I actually did that. The same way as including the sheets so i can use my sheets as level variables. Works perfect but global variables would be much easier to modify.

    Well thanks! I continue using the method i used and you just told.

    Thanks!

  • global variables are global.

    If you'd rather use local variables, which are local, just create a group and put all events in the eventsheet as subevents of the group. that way you could create new variables with the same name on every event sheet.

    Why you think that would be easier I have no idea, but it is possible.

  • Make different variables, set them differently or use instance variables for specific things?

  • Why not set the global variable back to 0 (or whatever you need) upon layout start?

  • Just to recap, GLOBAL means it is used everywhere, it is not just tied to the Sheet where you declared it. If you want to have variables with the same name in each layout, you can do like I do and add an invisible sprite to each layout with instance variables and set them to different values in each layout. Then you can just use one event to talk to them in each layout since they have the same name in each one.

  • I think topicstarter would rather not use events to set the variable.

    I guess he wants to see the global variable on the eventsheet, so he can insert/change the value there.

  • Hi all,

    Let me be clear on this one. I use my global variables as a kind of gamesettings when a game start. For example the time to spawn a object.

    This is different in every level with the same layout.

    One layout which can be seen as the game frame. In that layout i check which level is selected, and than i insert the information needed for that level. So again for example the spawn speed.

    This isn't hard to reach, what i was aiming for was the best way to do this.

    I learn everyday with CS2 and if i check the difference between my start period and now i already know alot more to save events etc.

    So sometimes i'm just not sure what the best way is to do something.

    Though all methodes above are pretty small and would work great.

    Thanks all!

  • Why not use an array and have an On Start of Layout event set a global index? Then you could use something like array[index] to access the variable.

  • Not sure what you want to do, but it sounds to me like you want to use a 1D or 2D array. Maybe it is for level properties like gravity and stuff?

    Then you could set up a gravity array, and to access it you just use gravity.at(currentlevelnumber) where currentlevelnumber is the level's index you are currently in.

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