0 Favourites

How do I know whether a value of an array is string or int?

  • so, imagine an RPG where you have healers that can restore a certain amount of HP, give a positive effect to your party members (attack up, speed up, defense up, etc.), or restore a negative effect (cures poison, paralisys, or confusion).

    I'm storing the skills in an array with the X row as the name, Y row as the target (single member, or all party members), and Z row as the effect. If the Z row is an int then I'll calculate the number of HP restored using a math formula, but if the Z row is a string then I'll do something based on it (whether raising stats or restoring negative effects)

    what I don't understand is how do I know whether the value I retrieve from an array is an int or a string?

    so maybe if I'm checking the value like this

        allSkills Value at (1, 1, 1) = isInt | (add action)
    [/code:3gygoytq]
    
    in javascript we can do typeOf but I'm not sure how C2 does this
    any suggestions would be appreciated, thanks.
  • You could check if int(Array.At(1, 1, 1)) > 0 then it's a number, as long as you don't have string values like "42", that are string representations of numbers..

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I don't have a string valued numbers, so it's safe. I just checked the manual and came up with the same solution. Thanks.

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