Undefined and (-1) being returned from variables

Discussion in 'Programming' started by Carcophan, Oct 8, 2019.

  1. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    53
    Hello everyone.

    I have a script that successfully generates a random map using ds_grid_create. Additionally, the mp_grid_draw(global.gridPathing) works as expected, showing proper pathing, etc.

    I can move around, collision works well. However, when I go to inspect any of the individual tile elements with RMouse pop up messages, I am getting -1 or undefined values returned on screen.

    I know I am doing something that is overly simple wrong, was hoping for an extra set of eyes. Searching for 'undefined' doesn't really yield much valid content. I keep experimenting with different concepts and ideas I see online but nothing seems to help.


    These are triggered from a mouse click event within a player step object. The grids are generated in the create event in a level object.

    The current code is more example than anything, used in an attempt to debug, not all the code is shown above.
    Code:
        show_message(string(tester1) + " and " + string(tester2) + " and AA = " + string(outVal11) + " and BB =  " + string(outVal22)
        + "  CX: " + string(cx) + " & MX: " + string(mx) + " & Mouse Index: " + string(tileIndexOfMouse)
        + "  & CharIndex: " + string(tileIndexOfChar) + " & Step Loc:  " + string(charStepLoc))
    So MX and the tileindexofMouse that is fed by mx are both returning -1's.




    Thoughts?
    Thanks in advance.
     
    Last edited: Oct 8, 2019
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,409
    For ds_grid operations, you would need to divide your mouse coordinates by your cell coordinates.

    For tilemap operations, your code doesn't seem to be making any sense - you are getting the same value into separate mx/my variables and then trying to use it as a coordinate? "mx" would already contain your desired tile data.
     
  3. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    53
    Thanks for the feedback Yellow.

    I hadn't ever had to explicitly divide the mouse_x _y by the tileWidth/roomwidth/whatever before, and was able to get X and Y tile information with similar code in a different project.

    My thought process is pointing to this being caused by how the grids are used/assigned.

    Code:
    for ( global.i = 0; global.i < mazeWidth; global.i++){
        for ( global.j = 0; global.j < mazeHeight; global.j++){
      
        global.cellFill = ds_grid_get(global.maze, global.i, global.j);
        //show_debug_message(string(global.cellFill))  //is working - is showing 1/0s. as expected
        draw_sprite(sCells, global.cellFill, global.i*global.tileSize, global.j*global.tileSize);
        tilemap_set(global.map_id, global.cellFill, global.i, global.j);
        tilemap_set(global.grid2, global.cellFill, global.i, global.j);
        }//draws map as expected
    }
    
    
    //and-or
    for ( global.i = 0; global.i < mazeWidth; global.i++){
        for ( global.j = 0; global.j < mazeHeight; global.j++){
       
            global.cellFill = ds_grid_get(global.maze, global.i, global.j);
            //show_debug_message(string(global.cellFill))  //is working - is showing 1/0s. 
       
            if(global.cellFill = 1) { 
                global.grid2[# global.i, global.j] = 1; 
                //tilemap_set(global.map_id, 1, global.i, global.j);
            }
       
            if(global.cellFill = 0) { 
                global.grid2[# global.i, global.j] = 0; 
                //tilemap_set(global.map_id, 0, global.i, global.j);
            }
            if(global.grid2[# global.i, global.j] = 0){
    
            }else{
                mp_grid_add_cell(global.gridPathing, global.i, global.j);  //works
            }
        }
    }
    
    
    
    
    
     
    Last edited: Oct 8, 2019
  4. Carcophan

    Carcophan Member

    Joined:
    Aug 4, 2019
    Posts:
    53
    I've tried the following, just for my curiosity:
    Code:
        var px1 = global._hp_map_id[# obj_Player01.x, obj_Player01.y]
        var px2 = global.gridHP_[# obj_Player01.x, obj_Player01.y]
        var px3 = global.cellFill[# obj_Player01.x, obj_Player01.y]
        var mx1a = tilemap_get_at_pixel(global._hp_map_id, mouse_x, mouse_y);
        var mx2a = tilemap_get_at_pixel(global._hp_map_id, mouse_x, mouse_y);
        var mx3a = tilemap_get_at_pixel(global._hp_map_id, mouse_x, mouse_y);
        var mx1b = global._hp_map_id[# mouse_x, mouse_y];
        var mx2b = global.gridHP_[# mouse_x, mouse_y];
        var mx3b = global.cellFill[# mouse_x, mouse_y];
        var mx1c = global._hp_map_id[# mouse_x div global.tileSize / 2, mouse_y div global.tileSize / 2];
        var mx2c = global.gridHP_[# mouse_x div global.tileSize / 2, mouse_y div global.tileSize / 2];
        var mx3c = global.cellFill[# mouse_x div global.tileSize / 2, mouse_y div global.tileSize / 2];
    
    show_message(" `: "            + string(px1)
        + " `: "                + string(px2)
        + " `: "                + string(px3)
        + " `: "                + string(mx1a)
        + " `: "                + string(mx2a)
        + " `: "                + string(mx3a)
        + " `: "                + string(mx1b)
        + " `: "                + string(mx2b)
        + " `: "                + string(mx3b)
        + " `: "                + string(mx1c)
        + " `: "                + string(mx2c)
        + " `: "                + string(mx3c)
    )
    
    And am still getting my -1's and undefined, instead of X/Y values or 1 and 0's or other values.
     

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