1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Problem with ds_grid_width & height

Discussion in 'Programming' started by AlexZ, Dec 10, 2018.

  1. AlexZ

    AlexZ Member

    Joined:
    Dec 10, 2018
    Posts:
    5
    Hi, I googled and couldnt find anything that'd help me and I really dont know what I'm doing wrong so I made an account here. hope u guys can help me.

    I got the following thing:

    grid_board = ds_grid_create (10, 10);
    var i, i2;
    for (i = 0; i < ds_grid_width(grid_board) ; i ++)
    {
    for (i2 = 0; i2 < ds_grid_height(grid_board); i2 ++)
    {

    // stuff happens here

    };
    };

    Then I get the following error:
    ds_grid_height argument 1 incorrect type (array) expecting a Number (YYGI32)
    at gml_Script_scr_setupboard (line x) - for (i2 = 0; i2 < ds_grid_height(grid_board); i2 ++)

    idk whats going on, shouldnt ds_grid_height(...) return a number? why does the error message say this is an array? I get the same error when I try to compare ds_grid_width in an if-statement like
    "if (i < ds_grid_width(grid_board) - 1) {
    //something
    };
    What am I doing wrong? :(

    thanks in advance for ur help.
     
  2. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,216
    Dunno if this'll fix it, but get rid of the ; after the curly brackets }

    There's literally no reason for that to be there.
     
  3. AlexZ

    AlexZ Member

    Joined:
    Dec 10, 2018
    Posts:
    5
    thats a thing i got used to. it doesnt really change the code.
    of course removing the ; didnt fix it but thanks for your answer.
     
  4. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,264
    Are you accessing grid_board anywhere in your code using square brackets? If you are doing this grid_board[0,0] , it will convert it into an array type.

    Make sure you are using the grid accessor (#):

    grid_board[# 0, 0]
     
    RefresherTowel likes this.
  5. AlexZ

    AlexZ Member

    Joined:
    Dec 10, 2018
    Posts:
    5
    Ah thats it! Thanks a lot IndianaBones!
     
    IndianaBones 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