How do I get initial value

0 favourites
  • 4 posts
  • Is there a way to display the initial value of instance variable in a text? Like I have a variable called life with initial value of say 30 which will decrease as the game continues. Different objects have different life of course so cant just put that 30 manually in the text. So can I just pick the initial value without creating another variable?

    Plus I want to pick the name as well but I guess same principle would apply there as well.

  • If what you're trying to do is what I think it is, you should be able to find the data (in this case the text) by calling objectname.variable name. So as an example, if you had a sprite called "Player" and wanted a textbox to display the life of 'Player' you would have an action that set the text of textbox to player.health (with no quotation marks around it so it was recognized as an expression).

    If you are doing this for multiple objects/instances, make sure you use something to pick the correct instance, such as 'pick nearest' or 'pick nth instance' or some such.

    Hope you have some luck in trying to solve your issue!

    Regards,

    Gideon

  • I got that part right. But the thing is that life value changes (e.g. if hit by bullet). I only want to pick the initial value from that instance variable, not the current value.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, then you need to also add a condition to state something like "on created" or "on start of layout" so that the first text it is set to is then fixed. Otherwise every time the condition is met it will re-evaluate the text in the variable.

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