[ RESOLVED ] Inventory - Item Pick-up Problem

D

Diveyoc

Guest
Can anyone help with this issue. I think it has to do with the arguments, but I don't have a good handle on using them yet. I've converted some code from a 1d array into a 2d array.
Now I'm trying to use a Right Mouse click event to pick up an item off the floor.
My sample item is just a red ball that is frame 1 of the spr_item, image index.

FATAL ERROR in
action number 1
of Mouse Event for Right Pressed
for object obj_red_ball:

Variable obj_red_ball.max_columns(100037, -2147483648) not set before reading it.
at gml_Script_scr_item_pickup (line 2) - for (c = 0; c < max_columns; c += 1)
_________________________________________________________________________

//==== Right Mouse Pressed Event
scr_item_pickup(1);
audio_play_sound(snd_whoosh,0,0);
instance_destroy();

//==== (Script) - scr_item_pickup
for (c = 0; c < max_columns; c += 1)
{
for (r = 0; r < max_rows; r += 1)
{
if (global.inventory[c,r] == -1) // If slot [c,r] is empty
{
global.inventory[c,r] = argument0;
return(1);
}
}
}
return(0);
 

Nux

GameMaker Staff
GameMaker Dev.
max_columns [...] not set before reading it
Your variable isn't initialised before you run this piece of code, so the program doesn't know what to do!
Initialise it in your obj_red_ball's create event, however, it seems like these are supposed to be global variables bound as characteristics to the array? if they are indeed located in another object you can use a global variable, or the "with" statement to perform this script on that controller object, instead of the item you are trying to pick up

P.s. - I would also suggest learning error messages; they really help; they give you all the information you need to debug. They're not there to be mean walls of text meaning "U DONE GOOF'D".
 
D

Diveyoc

Guest
Ah yes, initially I had these set as global variables but then I removed them. That is all I needed to do.
Thanks.
 
D

Diveyoc

Guest
Do you guys know what would be wrong with this command - button[c,r].slot = c & r;
I don't know what I should be using instead of c & r. It doesn't accept the other variations that I've tried.
I'm not getting any errors, but my inventory does all kinds of crazy stuff when I pick up an item.

show_inv = true
global.max_columns = 5;
global.max_rows = 5;

for (c = 0; c < global.max_columns; c += 1)
{
for (r = 0; r < global.max_rows; r += 1)
{
global.inventory[c,r] = -1;
button[c,r] = instance_create(0, 0, obj_invisible_button);
button[c,r].slot = c & r;
}
}
 

Nux

GameMaker Staff
GameMaker Dev.
(sorry for the late reply!)
I'm 50% certain you can't use dot notation on arrays, I could be wrong
If that's the case, you're going to have to put the value into a variable, alter it externally, and then insert it into the index of your array!

Code:
var inst = instance_create(0, 0, obj_invisible_button);
inst.slot = c & r; // alter instance externally, before putting it in the array
button[c,r] = inst; // put value into array
Alternatively, you do know & is bitwise, and it's not the same as "c" + "r" which would be "cr", instead it's checking the bits of each variable and comparing them if they are equal, if a both bits are equal, the result will be 1, else it will result to 0. e.g. 1&2 will return 0.
 
Top