0 Favourites

[r99] array breaks?

  • All,

    I don't know if this is a bug, or just my lack of programming knowledge. I created as simple a capx as I could the illustrate the problem.

    On program start, I define two arrays.

    #1

    box - (x,y,z)

    x = statistics for box ie, maxHP, atk, def, etc,

    y = boxes lvl, ie, 1, 2, 3, etc

    z = which box, ie, red or orange

    #2

    curVar    - (x,y)

    x = cur variables held, curHP, curLVL, curName, etc

    y = which box, ie, red or orange

    In my code, I use positions in the curVar array to call position in the statistics array,

    For instance,

    Example A

    "HP: " & curvar_array.At(3,menu_box.box)& "/" & box_array.At(1,curvar_array.At(2,menu_box.box),menu_box.box)

    and

    Example B

    "HP: " & curvar_array.At(3,select_box)& "/" & box_array.At(1,curvar_array.At(2,select_box),select_box)

    Example A calls from the instance variable set on the text box to display the info in the array.

    Example B calls from a global variable - select_box, which is defined based on where one clicks - to display the info in the array.

    Example A works fine, but Example B breaks the code.

    If the global variable - select_box - is set to 0, the code breaks even though I define the array at (0,0,0), but if on start of layout I set select_box to 999, the code works fine.

    The error message I get is:

    "THE PAGE AT THE LOCALHOST: 50000 SAYS:"

    "Javascript error!

    Uncaught TypeError; Cannot read property "0" of undefined

    localhost/Arr_pluging.js, line 102

    This is either a bug in Construct 2 or a problem in a third party plugin or behavior - please report in to the developer!"

    Here is the capx for reference:

    dl.dropbox.com/u/70332704/arrayerrormsg.capx

    Thanks for taking a look at this

  • Should be fixed in the next build. FYI it's because you are accessing arrays with NaN as an array index. (This is a sort of invalid value you get if you do things like divide a number by zero, since there is no possible result.) Now the array will just return 0 if you do that rather than causing that error, but you probably want to fix your events anyway.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks Ashley!

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