I cannot get around this and it's driving me crazy!
var i;
for (i=0;i<9;i+=1)
{if (controller.inv[i,1]<1)
{controller.inv[i,0]=-1;
}
}
that's the code i'm stuck on. controller.inv is an array that i'm using as an inventory. But whenever i start the game it says variable not recognized or array out of bounds. I declared the variable at game start and the error-checker says nothing while i'm actually writing the code. what am i doing wrong?
inv[i,0] identifies what item is being held in that slot and inv[i,1] tells how many are being held. This is supposed to make it so that if there is no amount of the item being held then the item being held is equal to nothing (aka -1).
debugging an array
Started by _255638, Feb 27 2012 01:03 AM
3 replies to this topic
#1
Posted 27 February 2012 - 01:03 AM
#2
Posted 27 February 2012 - 01:37 AM
You have to initialize every array slot, not just the first one. So...
So then whenever you do a check, each array slot that you actually use will have a value already. The above code should go in the create event of the controller.
var i;
for (i=0; i<9; i+=1){
inv[i,1] = 0;
inv[i,0] = -1;
}
So then whenever you do a check, each array slot that you actually use will have a value already. The above code should go in the create event of the controller.
#3
Posted 27 February 2012 - 03:30 AM
You have to initialize every array slot, not just the first one. So...
var i; for (i=0; i<9; i+=1){ inv[i,1] = 0; inv[i,0] = -1; }
So then whenever you do a check, each array slot that you actually use will have a value already. The above code should go in the create event of the controller.
no it's IF controller.inv[i,1]<1 THEN controller.inv[i,0]=-1. It needs to check if inv[i,0]=0 not make inv[i,0]=0.
#4
Posted 27 February 2012 - 03:59 AM
but if the variable position have not been assigned a value yet and is still undefined, then you are not allowed to compare it to anything..
so you should set all the slots to their empty value before using them, hopefully the controller does so in its create event?
another thing .. depending on the order things is performed in and what events this is, could be that that code triggers before the variables have been defined .. can be checked by putting a show_message in both places and see which ones triggers first .. if the wrong one, then re-place the 2 objects into the room starting with the controller
so you should set all the slots to their empty value before using them, hopefully the controller does so in its create event?
another thing .. depending on the order things is performed in and what events this is, could be that that code triggers before the variables have been defined .. can be checked by putting a show_message in both places and see which ones triggers first .. if the wrong one, then re-place the 2 objects into the room starting with the controller
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











