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

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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.
  • Try Construct 3

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

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

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