Bug with variables and tokenat?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi, I'm not sure this is a bug, I think so.

    The fact is that you can assign a value to a global integer from a string.

    The same case is not possible if the value is assigned to an instance variable.

    That is, the global variable "Variable1" can adopt a string integer value with tokenat but the instance variable of the sprite can not.

    CAPX

    https://www.dropbox.com/s/1r7nxlghztjwn4p/problem.capx?dl=0

  • The Instance Variable has to be (Type = Txt) to be used with a string, at the moment you have the Instance Variable as = Number,

    However, you can still use it with an Instance variable = Number as longs you convert it to a Number with the Expression "Int"

    Example:

    int(tokenat(text, 0, "|"))

    The only problem with this is that it will round the Number and you will lose the (.4)

    Not sure why Globals can use it and Instances Variables Not

  • Wrap it in float() to keep the fraction: float(tokenat(text, 0, "|"))

    If you set text to a number, then what you're trying to do is invalid. It might convert it and it might not - it seems minor since it's just a different kind of error fallback.

  • The Instance Variable has to be (Type = Txt) to be used with a string, at the moment you have the Instance Variable as = Number,

    However, you can still use it with an Instance variable = Number as longs you convert it to a Number with the Expression "Int"

    Example:

    int(tokenat(text, 0, "|"))

    The only problem with this is that it will round the Number and you will lose the (.4)

    Variable1 is of type int and the assignment can be done correctly.

    Why does not the same thing happen with the sprite instance variable?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wrap it in float() to keep the fraction: float(tokenat(text, 0, "|"))

    If you set text to a number, then what you're trying to do is invalid. It might convert it and it might not - it seems minor since it's just a different kind of error fallback.

    Ok, I understand, thanks.

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