GMS 2 Help with fatal error?

Discussion in 'Programming' started by Bladebss, Jan 10, 2019.

  1. Bladebss

    Bladebss Member

    Apr 8, 2018
    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.
  2. Danei

    Danei Member

    Mar 23, 2018
    Don't know if this is the source of your issue, but you have ++i in your for loop instead of i++.
  3. BaBiA Game Studio

    BaBiA Game Studio Member

    Jun 20, 2016
    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?
  4. Bladebss

    Bladebss Member

    Apr 8, 2018
    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);
  5. Taddio

    Taddio Member

    Nov 16, 2018
    Shouldn't it then be
    otheritem.shopinventorywidth, then?
    Edit: nevermind, I didn't catch that it was a global var., sorry!!
    Last edited: Jan 10, 2019
  6. Bladebss

    Bladebss Member

    Apr 8, 2018
    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.
  7. Bladebss

    Bladebss Member

    Apr 8, 2018
    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.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice