Instance variable and text box ?

0 favourites
  • 3 posts
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • Hello,

    How do I add to a text box the value of an instance variable ?

    Example :

    - Sprite has 2 instances variables : ID and Value

    - There 3 instance of Sprite on screen : ID = "Gold", ID="Health", ID="Time"

    - There is a textbox on screen

    - How do I set textbox's text to Value of Sprite instance ID="Health" ?

    something like :

    set text : "Player's hitpoints : "& sprite(ID="Health").Value

    I suspect some complex expression formula is involved here...

  • In Construct you pick the Sprite you want with conditions so on the left you pick sprite where variable = health, then with actions you say set text to Sprite.value.

    A more normal way though is to use a global variable for health then you can just say set text to health variable without using sprites.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sure, I'm aware of that but I know there is a more direct way.

    I managed to achieve this using Sprite IID.

    The syntax of the "set text" is :

    "Hitpoints : "&sprite(2).Value

    where 2 is the sprite IID and Value is the instance variable.

    So if Value=40, the code above displays for sprite IID=2 "Hitpoints : 40" in textbox.

    Instead of using IID, I would like to use another instance variable, for example Type="zombie"

    So the code would be something like :

    "Hitpoint : "&sprite(Type="zombie").value

    I tried many syntaxes but came up with nothing.

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