Disabling and enabling map layers with plotscripting?
Moderators: Bob the Hamster, marionline, SDHawk
Disabling and enabling map layers with plotscripting?
Is this possible? I'd like to do something where buildings and places you can go into have a normal outside view and then go to a cutaway interior view once you're inside. I think it'd be as simple as just adding an extra on-top layer with the outdoor view stuff (roof, parapets, etc.) and switching that layer off to reveal the cutaway interior view when stepping into a building, then switching the layer back on upon stepping outside.
I ctrl+F'd through the plotscript dictionary but didn't see any commands that appear to deal with switching layers on and off.
I'm going into more detailed map design now so I'd like to plan accordingly based on whether this is possible or not.
I ctrl+F'd through the plotscript dictionary but didn't see any commands that appear to deal with switching layers on and off.
I'm going into more detailed map design now so I'd like to plan accordingly based on whether this is possible or not.
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
I believe that <a href="http://hamsterrepublic.com/ohrrpgce/doc ... sible">set slice visible</a> is the command you're looking for.
What you'd need to do would be to get the handle of the slice that has the layer you're looking for with <a href="http://hamsterrepublic.com/ohrrpgce/doc ... ce">lookup slice</a>. You would then use set slice visible to show or hide that layer.
What you'd need to do would be to get the handle of the slice that has the layer you're looking for with <a href="http://hamsterrepublic.com/ohrrpgce/doc ... ce">lookup slice</a>. You would then use set slice visible to show or hide that layer.
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Shoot, realizing that I've never done plotscripts that deal with getting slice handles or anything like that. Hopefully I'll be able to figure this out.
Yeah, dismal failure so far, hspeak is telling me that I can't use = to make a variable something. I dunno what to do about that.
EDIT:
Specifically, lookup slice in plotdict has an example of getting a handle
variable(portrait)
portrait = lookup slice(sl:textbox portrait)
if(portrait) then(
replace portrait sprite(portrait, 5)
)
but hspeak doesn't allow "variable = " and gives me an error message: "unimplemented keyword/operator = is not permitted inside a script"
Here's what I attempted.:
Yeah, dismal failure so far, hspeak is telling me that I can't use = to make a variable something. I dunno what to do about that.
EDIT:
Specifically, lookup slice in plotdict has an example of getting a handle
variable(portrait)
portrait = lookup slice(sl:textbox portrait)
if(portrait) then(
replace portrait sprite(portrait, 5)
)
but hspeak doesn't allow "variable = " and gives me an error message: "unimplemented keyword/operator = is not permitted inside a script"
Here's what I attempted.:
Code: Select all
plotscript, hide exterior, begin
variable(overhead)
overhead = lookup slice(sl:map layer1)
set slice visible(overhead, off)
end
Last edited by Foxley on Sun Sep 21, 2014 8:08 pm, edited 5 times in total.
- Bob the Hamster
- Liquid Metal King Slime
- Posts: 7460
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
You are very close!
to assign a value to a variable, you use :=
to assign a value to a variable, you use :=
Code: Select all
plotscript, hide exterior, begin
variable(overhead)
overhead := lookup slice(sl:map layer1)
set slice visible(overhead, off)
end
Bob the Hamster wrote:You are very close!
to assign a value to a variable, you use :=
Code: Select all
plotscript, hide exterior, begin variable(overhead) overhead := lookup slice(sl:map layer1) set slice visible(overhead, off) end
Except, then I got another error message, but now I can't replicate it for some reason.... but getting the error message prompted me to try this:
Code: Select all
plotscript, hide exterior, begin
set slice visible(lookup slice(sl:map layer1), off)
end- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Cool. I can't wait to see this in action.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Here's a quick demonstration:sheamkennedy wrote:Cool. I can't wait to see this in action.
https://www.dropbox.com/s/mcq5ljb1e3r1f ... t.zip?dl=0
I put layers 0 and 1 below the walkabout layer and made layer 2 one of the exterior view layers (specifically the roofing), so if the hero walks in front of the building exterior on the bottom it won't overlay the building on top of the character's head.
- Pepsi Ranger
- Liquid Metal Slime
- Posts: 1419
- Joined: Thu Nov 22, 2007 6:25 am
- Location: South Florida
You may or may not need this advice, but I tend to find that it's best to plan ahead for the eventuality of needing more advanced layers by assigning layers 0-2 as bottom layers and 3 and 4 as overhead layers by default. This makes it easier to plan for more complicated designs without having to go back and rescript everything to account for layer changes. If your plan is to keep things simple, then maintaining the default layers (0,1 for bottom, 2 for overhead) is probably good enough. But if you want detailed roofs, grounds, or really, detailed anything, then you might want to set up each map with more layers and then fill them in as needed.
Place Obligatory Signature Here
Yeah, I was actually going to do that once I get real maptiles rolled out. It may get tricky, for example if I wanted to do an overhead layer that's for the interior view.
I think this might work:
Layer 0: Base background layer
Layer 1: Exterior view layer that is not overhead
Walkabout/NPC Layer
Layer 2: Interior cutaway view layer that is overhead
Layer 3: Exterior view layer that is overhead
Then I could make the hide/show scripts only switch visibility for Layer 1 and 3. I'd have to make sure that Layer 3 covers Layer 2, though, or else interior view stuff wouldn't be covered up when outside. Or, I could make Layer 4 a special/as-needed layer to cover up problem tiles in those cases.
I think this might work:
Layer 0: Base background layer
Layer 1: Exterior view layer that is not overhead
Walkabout/NPC Layer
Layer 2: Interior cutaway view layer that is overhead
Layer 3: Exterior view layer that is overhead
Then I could make the hide/show scripts only switch visibility for Layer 1 and 3. I'd have to make sure that Layer 3 covers Layer 2, though, or else interior view stuff wouldn't be covered up when outside. Or, I could make Layer 4 a special/as-needed layer to cover up problem tiles in those cases.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Another option that may relieve this, but could be more advanced to script, is:Foxley wrote:Yeah, I was actually going to do that once I get real maptiles rolled out. It may get tricky, for example if I wanted to do an overhead layer that's for the interior view.
I think this might work:
Layer 0: Base background layer
Layer 1: Exterior view layer that is not overhead
Walkabout/NPC Layer
Layer 2: Interior cutaway view layer that is overhead
Layer 3: Exterior view layer that is overhead
Then I could make the hide/show scripts only switch visibility for Layer 1 and 3. I'd have to make sure that Layer 3 covers Layer 2, though, or else interior view stuff wouldn't be covered up when outside. Or, I could make Layer 4 a special/as-needed layer to cover up problem tiles in those cases.
-Make each roof a backdrop slice.
example) House A could be slice 1, House B could be slice 2 etc...
-Then have a script which runs when the map initializes, the script will load each of the roofs in the corresponding (x,y) position on the map.
-Then make a second script which is triggered by zones. When you enter House A then zone 1 is stepped on, thus slice 1 is hidden. When you exit House A then zone 2 is stepped on, thus slice 1 is made visible. (Kind of like an on off switch for that house's roof.
Advantages for using this method:
1) Only the house your inside will have the roof removed
2) You can load all roof slices to a single map layer, thus all other layers will be free for complex layered drawing of maps
3) Since you are showing/hiding slices rather than a layer, you could create a room-by-room effect in which you could reveal 1 room at a time as the player traverses a castle for instance....
Disadvantages for using this method:
1) Slightly tougher script to set up
2) If house has a very large roof then you may have to load a group of slices, and hide a group of slices for that particular roof.
Last edited by sheamkennedy on Tue Sep 23, 2014 5:31 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Also I checked out the Cutaway test and it looks great so far.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Thank you!
Also, I think I've got this fully working, in case anyone is interested:
Also, I think I've got this fully working, in case anyone is interested:
Code: Select all
#***********************
#* Cutaway view toggle *
#***********************
# Use the following layers in this order:
# - Map layer 0: base background
# - Map layer 1: exterior view background
# - Walkabout/NPC layer
# - Map layer 2: interior view foreground
# - Map layer 3: exterior view foreground
# Then, place a step-on NPC with 'hide exterior' at the first step going into a building,
# and 'show exterior' at the first step going outside a building (e.g. the doorstep)
# Also, disable Map Layer 2 in the map editor if the map starts in an exterior view area.
# This prevents the interior foreground layer from being shown on top of the exterior background layer.
plotscript, hide exterior, begin
set slice visible(lookup slice(sl:map layer1), off) #-Turns off the exterior background layer
set slice visible(lookup slice(sl:map layer3), off) #-Turns off the exterior foreground layer
set slice visible(lookup slice(sl:map layer2), on) #-Turns on the interior foreground layer
end
plotscript, show exterior, begin
set slice visible(lookup slice(sl:map layer1), on) #-Turns on the exterior background layer
set slice visible(lookup slice(sl:map layer3), on) #-Turns on the exterior foreground layer
set slice visible(lookup slice(sl:map layer2), off) #-Turns off the interior foreground layer
end
Last edited by Foxley on Wed Sep 24, 2014 3:02 am, edited 1 time in total.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Thanks for sharing!
This also just lead me to another idea I had awhile back regarding faking transparencies. I was just thinking, what would happen if I used this code to make a foreground map layer flicker on, and off at a specified rate (example. every tick). I presume it would make it appear that the tiles on that layer would be 50% transparent. Now what if I made the map tiles on that layer look like clouds. This should make it appear as if my character is semi-visible while passing below these clouds. It could make for a nice effect, but I fear it may also slow down the game immensely depending on the size of the map.
I have seen people do rain-like effects in their games without noticeable slow downs though, so I could be wrong. I'll have to give it a try, but unfortunately don't have time at the moment.
This also just lead me to another idea I had awhile back regarding faking transparencies. I was just thinking, what would happen if I used this code to make a foreground map layer flicker on, and off at a specified rate (example. every tick). I presume it would make it appear that the tiles on that layer would be 50% transparent. Now what if I made the map tiles on that layer look like clouds. This should make it appear as if my character is semi-visible while passing below these clouds. It could make for a nice effect, but I fear it may also slow down the game immensely depending on the size of the map.
I have seen people do rain-like effects in their games without noticeable slow downs though, so I could be wrong. I'll have to give it a try, but unfortunately don't have time at the moment.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- Bob the Hamster
- Liquid Metal King Slime
- Posts: 7460
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact: