How do I get initial value

Get help using Construct 2

Post » Thu Jul 23, 2015 3:54 am

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.
B
4
Posts: 12
Reputation: 226

Post » Thu Jul 23, 2015 7:43 am

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! :D

Regards,
Gideon
B
10
S
1
Posts: 72
Reputation: 1,015

Post » Thu Jul 23, 2015 8:00 am

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.
B
4
Posts: 12
Reputation: 226

Post » Thu Jul 23, 2015 8:59 am

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.
B
10
S
1
Posts: 72
Reputation: 1,015


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests