GMS 2 [Solved]DoAdd :2: undefined value?

Discussion in 'Programming' started by Bladebss, Apr 17, 2019 at 6:01 PM.

Tags:
  1. Bladebss

    Bladebss Member

    Joined:
    Apr 8, 2018
    Posts:
    9
    hello, I am trying to set up a level up step event, I have a ds_grid I have added all the values to and use it to display the weapon stats I have called it eqip_inventory and is defined as global using globalvar.

    in the player step event I have some code:
    Code:
    if (ds_grid_get(eqip_inventory,13,0) > ds_grid_get(eqip_inventory,28,0)) {level_up = true ds_grid_set(eqip_inventory,11,0,ds_grid_get(eqip_inventory,11,0)+1)}
    if (level_up=true){ds_grid_set (eqip_inventory,14,0,ds_grid_get(eqip_inventory,13,0) *2);
                    ds_grid_set (eqip_inventory,24,0,ds_grid_get(eqip_inventory,24,0) + (ds_grid_get(eqip_inventory,21,0)div 3));
           ds_grid_set (eqip_inventory,25,0,ds_grid_get(eqip_inventory,25,0) + (round(ds_grid_get(eqip_inventory,22,0)/3)));
           ds_grid_set (eqip_inventory,27,0,ds_grid_get(eqip_inventory,27,0) + (irandom_range(1,5)));     
           ds_grid_set (eqip_inventory,28,0,ds_grid_get(eqip_inventory,14,0));
                       level_up=false;
     }
    
    [code/]
    
    but I get this error:
    DoAdd :2: undefined value
     at gml_Object_obj_player_Step_0 (line 284) -                 ds_grid_set (eqip_inventory,24,0,ds_grid_get(eqip_inventory,24,0) + (ds_grid_get(eqip_inventory,21,0)div 3));
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_obj_player_Step_0 (line 284)
    
    
    all the entries in the grid are numbers, some are set using code that refers to other parts of the grid or from a variable that uses code to do calculations and then sets the grid to the result.
    
    I think its the way im writing the code that is causing the error, like I need brackets some where I haven't got them or I cant do all this math and code where im putting it and I need to put the answers into a local var and then use that to do the rest of the code?
    
    can any one help, I just cant work out what I have done wrong?
     
  2. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,051
    First step is to change it into local vars. By not doing that, you're making it really hard to see what could be a very simple mistake. Name the vars appropriately according to what they do and then use them in the ds_grid_sets. Then if you don't figure out the problem while you're doing that, post your new and updated local var filled code for us to have a look at. This will also be where descriptive var names help us out a lot.
     
  3. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,402
    Apart from what @RefresherTowel says (which is indeed the first thing you should do), the fact that you are getting that error implies that you are trying to get a value outside of the bounds of the grid, which is returning "undefined", hence the doadd error.
     
  4. vdweller

    vdweller Member

    Joined:
    Jun 24, 2016
    Posts:
    96
    DoAdd error s happen when you try to add something that is not actually a valid number. Use show_debug_message for every value inside this faulty line in order to see what is returned individually, then you will be able to pinpoint the problematic value.

    Also brace yourself for an influx of posts stating that your coding style is crap and you must repent by saying "John Carmack" 1000 times.
     
  5. Bladebss

    Bladebss Member

    Joined:
    Apr 8, 2018
    Posts:
    9
    Ok after trying to set local variables and failing as they are not defined at the beggining of the game as i have not equiped the weapon. I then tryed seeing what the variable i was calling from the grid was using the debug message like vdweller suggested, and low and behold its was undefined... but why? I just dont get why, i mean i use the same code to set all the variables in the grid and just change the numbers and the other variables all work... so i think i have even bigger problems.lol

    I will continue investigating tonight and see if i can get to the bottom of this madness.

    Stay tuned for a new upload of code tommorow when i cant figure out what i have done wrong there lol

    Thanx for the help so far guys at least i have a start to figure out what im doing wrong.

    Who's john carmack? Isnt that the doom guy?The reason i dont know is probably the same as to why my code wont work lol
     
    Last edited: Apr 17, 2019 at 8:47 PM
  6. Bladebss

    Bladebss Member

    Joined:
    Apr 8, 2018
    Posts:
    9
    Omg! I CANNOT believe it! I found the problem and... it was that there was a space at the end of the value i was setting in the ds_map before the " so the key i was using to set the value that the grid was looking for in the map was not matching and making a new key and map pair with the space in.

    Now the only problem i have is the code that now works in terms of not crashing the game, doesnt do what i want it to.. as the values in the eqip_inventoryGUI dont update to the new ones so no level up ocurs.. im sure i will figure out why in good time tho.

    So thanx again every one! Couldnt have done it with out you! Cant belive the problem was so simple!
     

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