Finding Area & Location of Specified Zone / Layer Visibility

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Finding Area & Location of Specified Zone / Layer Visibi

Post by kylekrack »

I am working on having removable roofs for buildings in my current game, rather than use doors to transport to them. To do this, I am trying to use a map layer dedicated to roofs and zones on those tiles. Reading up in the dictionary, I'm struggling to find the possible commands, if any, to locate x and y values of a zone given a zone ID. I also can't find anything on the wiki. I assume it may not be easily possible.

Regardless, my next question would be what is the best way to toggle map layer visibility. If removing portions of a roof layer by zone is too complicated or impossible, I think making the entire layer invisible instead would suffice. However, I'm struggling with that as well. In custom, it's possible to disable layers in the editor, and I'd like to do something like that. I could write the map blocks all to 0, but I am wary about setting them back to their original values.

To clarify, I have a building with a stepon NPC in the doorway. When the player activates the NPC, the 'roof' of the building should disappear so the player can see 'inside.'
My pronouns are they/them
Ps. I love my wife
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hiding the entire roof layer will be very much the easiest way to do this.

Then you don't even need to find all the tiles in the zone, all you need to know is whether or not the hero is on the zone right now.

Code: Select all

if(read zone(1, hero X(me), hero Y(me))) then(
  # under a roof
)else(
  # out in the open
)
If you do really still want to find all the tiles in a zone, the easiest way to do this is simply to loop over the whole map.

Code: Select all

variable(x, y)

for(y, 0, map height -- 1) do(
  for(x, 0, map width -- 1) do(
    if(read zone(1, x, y)) then(
      # something that happens for all tiles in zone 1
    )
  )
)
Last edited by Bob the Hamster on Tue Apr 05, 2016 8:08 pm, edited 1 time in total.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Ah, I see. I will use that first bit you suggested. I don't want to lag out my main game loop by searching the entire map every tick. But now I know how to look for zones. Thank you!
My pronouns are they/them
Ps. I love my wife
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

I did this kind of thing back in 2014, when I'm back at home on my desktop computer I'll look for the thread. I believe I put an example script in it.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Hiding map layers seems to be a FAQ. Maybe it's worth adding a convenience script to be explicit, or add a FAQ on the wiki.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yeah! I would love a convenience script. That is a good idea
Post Reply