Qiso: Get all characters on map and check if character exists at specific tile

I’m using Qiso plugin and I have using the character concept for buildings (objects) placed by the using. I need to be able to:

  1. Check if there is a character/building on the tile the user tapped.
  2. List all the characters/buildings on the map

For the first need 1., I intended to use 

qiso.getCharacterData("Player")

But I need to provide the name of the object as a parameter, which I don’t necessarily have. What I know is the tapped coordinated. I couldn’t find a way to see if a character exists at these coordinates. Any idea how this can be achieved?

I was also thinking of building a table of objects/coordinated when adding the objects to the map and loop through this table when needed but that doesn’t seem optimal.

For the second request, I guess the answer to 1. will help me.

Bonus question: If the Character concept of Qiso is not adapted to adding/moving/removing Buildings/objects, I’m open to any suggestion; but from what I can see it seems appropriate.

For performance, you’d be better off using the laying mechanic really. Think of the whole thing as working like a 3D array - the grid is your first dimension, and each tile contains layers as your second dimension. You can use addToTile() and removeFromTile() then, to place/remove buildings.

https://qiso.qweb.co.uk/documentation/data/map-handling/functions/addtotile

https://qiso.qweb.co.uk/documentation/data/map-handling/functions/removefromtile

In addition to this performing better than using to characters for them, it means that if you then added characters as well as buildings, you could use enablePath() and disablePath() to prevent characters from walking over your buildings.

Additionally, you could then create timers and use replaceInTile() to animate your building sprites.

To answer your original question - if you switched to using the layers mechanic, you could then use getTileData() to grab the layers currently on a particular tile, and iterate them to see if any are the building you’re looking for.

https://qiso.qweb.co.uk/documentation/data/map-handling/functions/gettiledata

As for listing all of the buildings on the map - you could technically iterate the tile data to determine this, but with large maps this could be a performance killer. You’d be much better off maintaining your own list and just incrementing/decrementing counters as the player adds/removes your buildings. Apart from anything else, you’d then only need to do this as part of the placement event rather than having some kind of loop constantly monitoring for changes.

Awesome! working with layers is indeed the best and addToTile and removeFromTile are great.

Could you also provide a example of setTileData? The documentationis pretty limited.

Thanks!

Glad that worked. Do you have a demo build/video of what you’ve produced so far? I’d love to see how this is coming along =).

setTileData is basically the reverse of getTileData. Idea being that you can use getTileData to grab a table, make amends to that table directly, and then just pass it back to the engine. Or so that you can pass a table of data to create a tile from during initial load, etc. The format should be exactly as per the format getTileData responds with, so the easiest way to understand it is to create a simple Tiled map, load that up, then use getTiledData to see how the engine converted the original Tiled data and that’s exactly the format you’d want to pass to setTiledData() to create the same tile set-up directly.

So, something like this should work:

-- sets 3 layers of tile data for the tile at x10, y20. -- The numbers in the tile data would be the sprite references exactly like you use with addToTile() etc. -- If the layer names don't exist yet, use recordNewLayer() first to tell the engine that this new layer exists. The renderer iterates the tile layers in the order they're added via this function so if it doesn't know that a layer exists, it won't render it. If you imported a Tiled map that already had the layers defined, you can assume the engine knows about them already. x = 10 y = 20 tableData = { ["ground layer"] = 1, ["buildings layer"] = 2, ["some other layer"] = 3 } qiso.setTileData(x, y, tableData)

Great, thanks!

I will provide a video in a couple of weeks, it’s still to early to show anything fun :slight_smile:

I’ll hold you to that! :grin: