How could I read strings as a value?

0 favourites
  • 8 posts
From the Asset Store
A collection of a mix of percussion and orchestral string loops, including 20 musical sketches.
  • If I have global variables Unlock_Level_1(1),(Unlock_Level_2(0) ,Unlock_Level_3(0)

    Then how could I use a string as a value?

    Set "Unlock_" & "LayoutName to 1

    I tried to use int("Unlock_"&"LayoutName") but it just won't read it as a value for a variable.

  • Yeah, afaik you can't use a string to refer to a variable name like you can with a layout name (e.g. Go to layout "Layout " & variable).

    Was looking to do that myself a while back, and the best solution I found was adding the variables to an array. (thanks to Joe7 for the suggestion)

    What also should work is - if you have "levelnames" - is storing at the beginning all names in a global 1d-Array eg:

    myLevelNames_Array= ['The first one','Second','Final Stage']

    and load the right value on start of each layout to the current Layout:

    LevelLabel- set Text -> myLevelNames_Array.At(current_level-1)

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

    Would that do the trick in your case?

  • You could also use a global Dictionary object, which allows you to set and get keys by a string expression, so you can use the expression you gave above.

  • Ah, of course. I forgot about the dictionary plugin, wasn't added yet when I was looking to do this. <img src="smileys/smiley20.gif" border="0" align="middle" />

  • Thanks Ashley and The dictionary worked perfectly and will save a lot of work from me. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • what does dictionary used for? i mean examples because i really didn't know what does string mean :

    <img src="http://i46.tinypic.com/4tni1l.png" border="0" />

    i know it has keys and values but what the different between it and the global variables or arrays

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • With this dictionary you can create/destroy "Global variables" called "keys" on the fly and you can name them as you like.

    My problem was that the global variables I had created came out as a readable text and I was unable to use them as a value to compare with anything else than other readable text. With this dictionary I'm able to store values with names and call or compare them whenever I like. I was now also able to show text 'new high score' to the player if the score was better than the previous one stored into my Dictionary "key" "HighScore_"&LayoutName

  • zsangerous - did you read the Dictionary manual entry which has a description? If you ever wonder what a feature is for or what it does, looking it up in the manual should be the first thing you do.

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