1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

(Solved)help me understand what im doing wrong

Discussion in 'Programming' started by EvanSki, Feb 12, 2019 at 5:33 PM.

Tags:
  1. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    Code:
    cmd_list_size = 9; //max size of grid
    cmd_list = ds_grid_create(1,cmd_list_size); //create grid
    ds_grid_clear(cmd_list,0);
    
    var grid = cmd_list;
    
    //set all commands to false
    for (var i = 0; i < cmd_list_size; i++)
    {
        ds_grid_add(grid, 1, i, false);
    }
    
    //COMMANDS                         
    grid[# 0, 0] = "LOGOFF";
    grid[# 0, 1] = "HELLO"; 
    grid[# 0, 2] = "2"; 
    grid[# 0, 3] = "3"; 
    grid[# 0, 4] = "4"; 
    grid[# 0, 5] = "5"; 
    grid[# 0, 6] = "6"; 
    grid[# 0, 7] = "7"; 
    grid[# 0, 8] = "8"; 
    grid[# 0, 9] = "9"; 
     
    Debug_SendGameStructure: packet size 72259
    Grid 0, index out of bounds writing [1,0] - size is [1,9]
    Grid 0, index out of bounds writing [1,1] - size is [1,9]
    Grid 0, index out of bounds writing [1,2] - size is [1,9]
    Grid 0, index out of bounds writing [1,3] - size is [1,9]
    Grid 0, index out of bounds writing [1,4] - size is [1,9]
    Grid 0, index out of bounds writing [1,5] - size is [1,9]
    Grid 0, index out of bounds writing [1,6] - size is [1,9]
    Grid 0, index out of bounds writing [1,7] - size is [1,9]
    Grid 0, index out of bounds writing [1,8] - size is [1,9]
    Grid 0, index out of bounds writing [0,9] - size is [1,9]


    But heres the thing, the ds_grid works fine and is filled with all the information I want in the correct places
    I dont understand at all, what the problem is
     
    Last edited: Feb 12, 2019 at 5:40 PM
  2. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    482
    You are creating a grid size of 1x9 and trying to store values in a grid of size 2x9 as far as I can tell.

    Change the grid size to 2x9 at creation.
     
  3. immortalx

    immortalx Member

    Joined:
    Sep 6, 2018
    Posts:
    161
    Code:
    ds_grid_add(grid, 1, i, false);
    You first dimension has a size of 1, so the only index there is zero. Change your code to
    Code:
    ds_grid_add(grid, 0, i, false);
     
  4. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    it gives me the same error but the 1's become 2's
     
  5. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    changing this to 2
    Code:
    cmd_list = ds_grid_create(2,cmd_list_size); //create grid
    gives me this
    Grid 0, index out of bounds writing [0,9] - size is [2,9]
     
  6. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    2,993
    Also increase the height from 9 to 10.
    you set cmd_list_size to 9, but you try to fill 10 spots in height.
     
  7. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    737
    If your second grid dimension is 9, you can only use 0 through 8 indices.
     
  8. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    changing that keeps all but the error above, and does not fill the slots with them being false
     
  9. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    Code:
    cmd_list_size = 10; //max size of grid
    cmd_list = ds_grid_create(2,cmd_list_size); //create grid
    ds_grid_clear(cmd_list,0);
    
    var grid = cmd_list;
    
    //set all commands to false
    for (var i = 0; i < cmd_list_size; i++)
    {
        ds_grid_add(grid, i, 0, true);
    }
    
    //COMMANDS                         
    grid[# 0, 0] = "LOGOFF";
    grid[# 0, 1] = "HELLO";
    grid[# 0, 2] = "2";
    grid[# 0, 3] = "3";
    grid[# 0, 4] = "4";
    grid[# 0, 5] = "5";
    grid[# 0, 6] = "6";
    grid[# 0, 7] = "7";
    grid[# 0, 8] = "8";
    grid[# 0, 9] = "9";
    

    Debug_SendGameStructure: packet size 72287
    Grid 0, index out of bounds writing [2,0] - size is [2,10]
    Grid 0, index out of bounds writing [3,0] - size is [2,10]
    Grid 0, index out of bounds writing [4,0] - size is [2,10]
    Grid 0, index out of bounds writing [5,0] - size is [2,10]
    Grid 0, index out of bounds writing [6,0] - size is [2,10]
    Grid 0, index out of bounds writing [7,0] - size is [2,10]
    Grid 0, index out of bounds writing [8,0] - size is [2,10]
    Grid 0, index out of bounds writing [9,0] - size is [2,10]

    and there not being set to true
     
  10. immortalx

    immortalx Member

    Joined:
    Sep 6, 2018
    Posts:
    161
    It seems you are confusing size with what the indices for accessing the grid should be. You set your grid to have a size of 1,9. That means that for the first dimension the minimum (and only) index is zero.
    For the second dimension the minimum index is zero and the maximum is 8.

    EDIT chamaleon beat me to it!
     
  11. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    482
    Show us your modified code.

    You created a grid of size 2x10 now (as stated in your error) but in your loop are incrementing the x-axis instead of the y-axis. Notice how it says out of bounds [9, 0].

    Change that.
     
  12. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    what I want is a grid with two columns 0,1
    column 0 holds the command name
    column 1 holds wither its true or false
     
  13. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    482
    Alright. My post still stands. Your initial code looped through your rows at column 2. Your modified code is looping through columns at row. This is incorrect, change it back.

    This is causing the error because you are trying to loop through 10 columns when you defined 2.
     
  14. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    changing
    Code:
    ds_grid_add(grid, i, 0, true);
    to
    Code:
    ds_grid_add(grid, 0, i, true);
    Now My problem is that column 1 is not being filled its just stuck at 0
     
    Last edited: Feb 12, 2019 at 6:36 PM
  15. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    289
    Binsk likes this.
  16. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    737
    I think you're best served by showing complete code snippets as you change things. Anyway, why would column 1 be filled if you are modifying the content in column 0? If you want to modify column 1 use 1 as the index, not 0. And why do you swap column and row indices? Pick one and stick with it while keeping the grid construction consistent with the choice you make throughout your code. And do look up what ds_grid_add() does, so you are not surprised later. It does not just set a value, it changes the existing value by performing addition (or string concatenation if the grid cell contains a string), and does not allow for different types between what is stored before and what is given as an argument to add.
     
    EvanSki likes this.

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