Variables in text not updating properly

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • 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?

  • 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.

  • 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.

    [quote:3o4gdtrk]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?

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > 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.

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