Variables in text not updating properly

Discussion and feedback on Construct 2

Post » Sun Nov 27, 2016 1:14 am

Hey,

The problem is simple, I'm trying to set a text to a variable that is equal to the health points of a game object. But, the text is not being updated properly, it seems it's just not updating at all, or having a big delay between changes (even if I use it at Every tick).

Also, I see in the debug that this variable is being changed normally. The problem is only in updating the text. Anyone know why this is happening? Never had this problem before with variable in texts. Thanks in advance! =)

http://imgur.com/L8u63Aw
Image for better explanation:

- HealthT1D1 and others: text I want to set
- torre01Deus01.vida and others: variable of health points

P.S: The first ones (manaDeus01 and manaDeus02) is working normally.
B
13
S
6
Posts: 9
Reputation: 1,093

Post » Sun Nov 27, 2016 2:20 am

@Lucatiel641

Can't see an issue so far.

What kind of variables do you use?
How do you trigger a change in values?

Can you reproduce the problem in a smaller capx that you could share?
B
34
S
9
G
3
Posts: 206
Reputation: 7,851

Post » Sun Nov 27, 2016 3:00 am

Instead of using "set text to baseDeus01.vida" try using "set text to str(baseDeus01.vida)"

If the vida variable is a number it should work if you convert it to a string to use in the text object.
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Sun Nov 27, 2016 3:14 am

They're instance variables from the game object itself (I have two towers with 2 different health bars).

They are triggered in various events, for example, when a fireball collides with them, a minion shoots at them. It's basically a Clash Royale for study purposes.
But the numbers are changed only with random events, sometimes the fireball does, and sometimes doesn't.
I'm also double checking the triggers to see if there is a problem, but the variable in the debugger is OK.

Here is a simple example in my game capx.

http://imgur.com/jSKKiXq

reads: thunder > on collision with tower01Player02 > is not invulnerable > subtract 25 from HP > set text to variable

The 'invulnerable' variable is only set to true when the player uses a shield, so it's always false.

Also, here it is the capx with the example (that works and updates fine) from a trigger I got in my game.

https://www.dropbox.com/s/rsr85gq6h2b6u9n/DamageSample.capx?dl=0

Weird thing is, I have a catapult-like character that shoots projectiles at the tower, and strangely, this works very well. But the fireball neither the thunder works.

Post by andreyin » Sun Nov 27, 2016 3:00 am
Instead of using "set text to baseDeus01.vida" try using "set text to str(baseDeus01.vida)"

If the vida variable is a number it should work if you convert it to a string to use in the text object.


I did the way you said and works like a charm now!
But why? Isn't the common way supposed to work too?
B
13
S
6
Posts: 9
Reputation: 1,093

Post » Sun Nov 27, 2016 3:31 am

Lucatiel641 wrote:I did the way you said and works like a charm now!
But why? Isn't the common way supposed to work too?


It's not supposed to. I'm not sure but I think it depends on your code and how your variables are set up. The text object is made only to display text, so you can use str() to convert anything into text.
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Sun Nov 27, 2016 3:36 am

andreyin wrote:
Lucatiel641 wrote:I did the way you said and works like a charm now!
But why? Isn't the common way supposed to work too?


It's not supposed to. I'm not sure but I think it depends on your code and how your variables are set up. The text object is made only to display text, so you can use str() to convert anything into text.


Oh, okay then. I'm not really used to game programming at the moment, didn't know about this cast in Construct 2. Thank you for your time! :)

EDIT: Thanks for your time too, MACPK. :P
B
13
S
6
Posts: 9
Reputation: 1,093


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 17 guests