Set value (by name)?

0 favourites
  • 14 posts
From the Asset Store
The collection includes pre-categorized selections that can be the definitive tone setting backdrop to gameplay.
  • Hey there,

    I'm trying to access a variable by using a string and not by selecting it in the list. Something like the "Go to layout (by name)"

    For example, I have a clickable object with a local variable "target"

    If target = "my_layout_name", I can have a script to load the layout with this name.

    But if target = "my_variable_name", I cannot find a way to set the value of the global variable with the name "my_variable_name".

    Hope that makes sense!

    Thanks =)

  • You'd probably want to use an array for this, instead of individual variables. Then you can just reference an index.

  • Oh, thanks! =)

    I'm surprised there isn't a more convenient way to do it. If I access the variables with numbers (array index), my script will become really hard to read :o

  • Ezhaac

    r91 has dictionary plugin. It's a 1d hash table.

  • Nice =)

    Can't wait to get my hands on the next release.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Out of curiosity, why do you need to be able to access your variables using a string? That can get messy - especially when you decide to change a variable name. Perhaps there is a more elegant solution that we could figure out, if you don't mind mentioning the specific problem.

  • Ezhaac

    r91 had released.

  • Dalal

    I'm working on a kind of point & clic game, using multiple photos as screens. I'll use a layout for each photo with an include pointing on a unique event sheet.

    On each layout, there are clickable object (for example: a mecanisme that can be activated, a door that can be used to go elsewhere, etc). Each object is a sprite which can have 1 or 2 instance variable called "target" and "flag".

    The "target" variable is the name of the layout that will be open when the player clic on the thing, and "flag" is the name of the boolean variable that is triggered. (if the object is a simple door and not a mecanism, it doesn't have a "flag" variable)

    The idea behind this structure is to have one master event sheet used by all my layouts, allowing me to simply position the clickable object on the scenes, without having to duplicate code each time.

    It may not be the best solution but I haven't programmed for several years, now, so, that's the best I've found yet :D

    rexrainbow

    I cannot find the r91. Is there some other download page for beta releases?

    scirra.com/store/free-html5-game-engine

  • Ezhaac

    scirra.com/construct2/releases/r91

    Yes, it's a beta release.

  • Thanks! <img src="smileys/smiley41.gif" border="0" align="middle" />

  • I'm having trouble using the dictionary plugin but I guess that's some very basic issue, so I don't know if I could open a new topic for that :o

    I have 2 layouts. I have added the dictionary in the first layout and I cannot access if from the second layout. I thought it would be shared like global variables but maybe I have something to do on the second layout?

    Here is my test Capx (very simple, with only the 2 layouts and a few test code)

    docs.google.com/file/d/0B7Un7Ec0OEI3czJTNF80RkdyZ0k/edit

    Thanks <img src="smileys/smiley12.gif" border="0" align="middle" />

  • Hey there,

    I'm still looking for the right way to use the dictionary. There is no documentation on the feature at the moment, probably because it's still on the beta release =)

  • It's the same as an Array or any other object. It's specific to one layout unless you set it to global in the object type properties.

  • Ok, indeed, that was very basic :D

    Thanks a lot =)

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