Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
object in square brackets ? — Gideros Forum

object in square brackets ?

chuz0chuz0 Member
edited January 2016 in General questions
Sorry if it's a noob question...
I was playing around with TileMap, and with the class Tilemapmultiple.lua (from @atilim I think...) I cannot understand what this piece of code does :
if tilemaps[tileset] then
						tilemap = tilemaps[tileset]
					else
tilemaps is a table, so I was expecting tileset to be an integer (position in the table), but it's an object... so, what does it do exactly ?


Comments

  • I don't know the code you are referring to but tileset looks like an offset to me (so integer).

    The if statement is checking that it is not nil, if not it is assigning whatever is in the table at that location to tilemap.
  • piepie Member
    Just to add a bit to @ChrisF answer, tileset could also be a string since lua accept both value types as table index.

    @chuz0 Post a link to the lua file or a "larger" piece of code :)
  • Hi @pie and @ChrisF, sorry I just posted a bit of code assuming it was well known.
    here : http://giderosmobile.com/forum/discussion/699/using-tiled/p1
    is the thread where @atilim posted an example with tilemapmultiple class.
    Thanks for the clarifications, although I don't fully understand it...
    Once stored it in a table with a string/object index, how can I iterate through the items to find what I'm looking for ?
  • piepie Member
    @chuz0 I played a bit with tilemaps but always took the part of code in your question as a dogma... :D
    I may be wrong, but I think it's just using the lua address of the current tileset (as returned by gid2tileset) as an index for tilemaps table.

    To iterate through a table you can use pairs and ipairs, however from the main topic I assume you need to iterate through a TileMap instance to get/set tiles/objects/enemies.

    Maybe there are better ways to do that, but nobody shared them so you have only my examples to check :P
    Basically I save references to anything I need to access later (you lose control over local objects outside the scope in which they're created).

    This is some way to get/setTile on a certain layer
    http://giderosmobile.com/forum/discussion/comment/43246#Comment_43246

    This is to set properties/place enemies/objects in tiled and retrieve them in your game
    http://giderosmobile.com/forum/discussion/comment/39233#Comment_39233

    Hope this helps

    Likes: chuz0

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks @pie, I was checking those threads too. It's that I didn't understand the indexing bit. I'll take a look on pairs and ipairs.
Sign In or Register to comment.