• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Help with fatal error?

B

Bladebss

Guest
Hello, i am currently trying to learn GML to make a game.

I have got some stuff down but i have run across this fatal error and i just cant work out whats gone wrong.

Fatal error in
Action number 1
Of key press event for <shift>key
For object obj_inv_shopGUI:

Ds_grid_height argument 1 incorrect type (undefined) expected a number (YYGI32)
At gml_script_s_additem (line 18) -for (i=0; i <ds_grid_height (gridtoaddto); ++i)

######
Stack frame is
Gml_script_s_additem (line 18)
Called from - gml_object_obj_inv_shopGUI_keypress_16(line 4) - script_execute(ds_grid_get(shopinventory,4,s_itemselected));

I cant work out why its doing this as its an argument i set up where argument 0 out of 6 is gridtoaddto

And gridtoaddto = shopinventory in the script so i have this..
s_additem (shopinventory, banana,1,"tasty banana", spr_banana, s_buyitem(), obj_banana)


Shopinventory is a global variable and so is s_itemselected

Shopinventory = ds_grid_create(shopinventorywidth,1);

Shopinventorywidth =6;

So shouldnt the grid hight be getting a number from shopinventory and then adding 1 every time i add an item.

I could take some screens of my code if it helps.

I just cant work out whats gone wrong

I have the same set up for my player inventory but using different global variables and that works fine.

The idea was i could add stuff to the shop inventory on activation, and replace the script for using the item, with one for buying the item, where it adds the item to playerinventory but with the propper script for when its used buy the player.

So in the s_buyitem script brackets i have the same arguments to fill in but i just swaped the buyitem script for the eatbanana script. I omitted the arguments in my example abouve for the buyitem script cus im lazy lol but as the brakets are there i wundered if its running the code ontop and some thing is bugging out.
 
D

Danei

Guest
Don't know if this is the source of your issue, but you have ++i in your for loop instead of i++.
 
Shopinventory = ds_grid_create(shopinventorywidth,1);

Shopinventorywidth =6;
Why are you setting the variable to define the width of the grid after you have tried creating the grid with that variable for the width? Surely that is going to cause problems if you have not actually defined a width for the grid. Shouldn't Shopinventorywidth=6 come before you create the grid?
 
B

Bladebss

Guest
It is defined in a different object that initialises the grid. I have it in the background of the room.

Under its creation code is says.
Globalvar shopinventory, shopinventorywidth;

Shopinventorywidth = 6;
Shopinventory =ds_grid_create(shopinventorywidth, 1);
 
T

Taddio

Guest
It is defined in a different object that initialises the grid. I have it in the background of the room.
Shouldn't it then be
otheritem.shopinventorywidth, then?
Edit: nevermind, I didn't catch that it was a global var., sorry!!
 
Last edited by a moderator:
B

Bladebss

Guest
I feel like i need to post the code as its quite hard to explain the whole thing.

I have a feeling its not the fatal error thats causing the fatal error if that makes sence, but some other effect that is causing this to happen. Perhaps with my scripts or a rouge 'with' statement thats changing the variable.
 
B

Bladebss

Guest
Never mind. I think it was a problem with my scrips and having brakets and then having the script in the brakets with brakets.

Eather way i found a different way to get it to do what i want, not so elegant but at least it works. I just have it spawn the object on the player and then it collides with the player instantly and is put into the player inventory.
 
Top