How do I change global variables by name

0 favourites
  • 6 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.
  • I'd like to make an object (myButton) with 2 variables:

    • variableName
    • variableValue

    And then if player presses this object change global variable thats name is [myButton.variableName] to [value myButton.variableValue].

    Now I can only change global variables selected from dropdown list.

    Is it possible?

  • What result you want to achieve with all this? Is there any need to change variable name.

    Tell your aim and maybe I will tell you other solution.

  • I'm confused, you want to change the name of the variable, or you want to change the variable that the button effectss

  • As result I'd like to have universal button that can change global variables. When building my options menu I'd like to put one object (button) that determines what variable to change and how.

    Example:

    I have global variables:

    1. setupSound

    2. setupMusic

    3. setupSpecialEffects

    and so on.

    On the options layout I'd like to put 3 instances of sprite object - buttons. In every button I determine what variable to change and how:

    Button instance 1:

    • variableName = "setupSound"
    • variableValue = 1

    Button instance 2:

    • variableName = "setupMusic"
    • variableValue = 1

    So pressing Button instance 1 will set global variable "setupSounds" as 1.

  • You can use a dictionary for this, but you can't address global variables by name.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'd like to make an object (myButton) with 2 variables:

    - variableName

    - variableValue

    And then if player presses this object change global variable thats name is [myButton.variableName] to [value myButton.variableValue].

    Now I can only change global variables selected from dropdown list.

    Is it possible?

    If they are not in the drop down list then you may have accidentally turned it into a local variable by moving it under an event block. A good rule of thumb is to put them at the top of the event sheet, and leave them there. Global has a earth icon, the local one has a diamond icon.

    The global variable might be under the block as well, and this just wont do. C2 reads the sheet from top to bottom iirc.

    I try to keep the Global variables on their own event sheet. That way to does not matter wher I put them on that sheet. Makes it easier to reference your variables too. You have one simple list where you go to add the tweeks, rather than scrolling through a bunch of event sheets.

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