Question - Code layer_get_id() / layer_tile_create() bug?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Bros Before Giraffes, Jan 16, 2017.

  1. Bros Before Giraffes

    Bros Before Giraffes Member

    Joined:
    Jun 24, 2016
    Posts:
    30
    I want to use tiles to add blood decals to the floor, but the tiles are not being created and I keep getting this in the output window
    [​IMG]
    I'm using this code to place the tiles:
    Code:
    var n = layer_get_id("tiles");
    layer_tile_create(n,x,y,tile_blood,1,1,16,16);
    
    As you can see, I do have a tiles layer named "tiles" in the room.
    [​IMG]

    I checked the manual to make sure I was using the functions right, but it seemed like it was okay.
    Could this be a bug or is there something I'm still doing wrong?

    EDIT: I just read about layer_tile_create() in the manual. It says I should never use it outside of compatibility scripts. Why is that? And if I can't use this function, how do I add tiles to a tile layer?
     
    Last edited: Jan 16, 2017
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,892
  3. Ariak

    Ariak Member

    Joined:
    Jun 20, 2016
    Posts:
    91
    @Nocturne
    This is a bug in GMS2. `layer_get_id` of a tilelayer will return -1 (couldnt find any) if there is no Tileset assigned in the room editor. The bug has been reported.

    As a result you will either have to create the layer + tilemap through code, OR set a tileset to the layer in the room editor.

    The function you are looking for is called layer_tilemap_create - not layer_tile_create.

    There are indeed undocumentend layer_tile functions, but these require a unique tile element id. These seem to be new functions where we can set the blend,alpha etc. of indivudal tiles and are probably part of a future update. EDIT: as nocturne pointed out i was wrong - they are for compatability scripts.
     
    Last edited: Jan 16, 2017
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,892
    The functions the user is referring to are not "undocumented functions that will be part of a future update". They are undocumented functions that are only for internal use. http://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/compatibility_functions.html

    As for what the user says, I misread the full topic and they are missing a step... they need to get the tilemap layer that the tile is on, not just jump from the layer ID to the tile. You create a layer, then you create a tilemap and THEN you add/remove/change the tiles on the tilemap.

    So:

    Code:
    var n = layer_get_id("tiles");
    var m = layer_tilemap_get_id(n);
    tilemap_set_at_pixel(m, TILE_INDEX_VALUE, x, y);
    
    :)
     
    Ariak likes this.
  5. Bros Before Giraffes

    Bros Before Giraffes Member

    Joined:
    Jun 24, 2016
    Posts:
    30
    Thanks for the help guys! I got the tiles to spawn, but they automatically snap to a 16x16 grid. Is there a way to create tiles at any point in the room instead of snapping to the grid?
     

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