Disabling and enabling map layers with plotscripting?

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Disabling and enabling map layers with plotscripting?

Post by Foxley »

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.
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

Post by BMR »

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.
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
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Awesome! Thank you. I'll give this a try today. :)
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

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.:

Code: Select all

plotscript, hide exterior, begin
	variable&#40;overhead&#41;
	overhead = lookup slice&#40;sl&#58;map layer1&#41;
	set slice visible&#40;overhead, off&#41;
end

Last edited by Foxley on Sun Sep 21, 2014 8:08 pm, edited 5 times in total.
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

You are very close!

to assign a value to a variable, you use :=

Code: Select all

plotscript, hide exterior, begin
   variable&#40;overhead&#41;
   overhead &#58;= lookup slice&#40;sl&#58;map layer1&#41;
   set slice visible&#40;overhead, off&#41;
end
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

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&#40;overhead&#41;
   overhead &#58;= lookup slice&#40;sl&#58;map layer1&#41;
   set slice visible&#40;overhead, off&#41;
end
:D You are a lifesaver! Now I know how to assign values to variables.

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&#40;lookup slice&#40;sl&#58;map layer1&#41;, off&#41;
end
And that works too. Only one line! Then I replaced off with on for "show exterior" in a separate script and it works absolutely perfect. Yay!
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

sheamkennedy wrote:Cool. I can't wait to see this in action.
Here's a quick demonstration:
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.
User avatar
Pepsi Ranger
Liquid Metal Slime
Posts: 1419
Joined: Thu Nov 22, 2007 6:25 am
Location: South Florida

Post by Pepsi Ranger »

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
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

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.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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.
Another option that may relieve this, but could be more advanced to script, is:
-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
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Thank you!

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&#58;
#	- Map layer 0&#58; base background
#	- Map layer 1&#58; exterior view background
#	- Walkabout/NPC layer
#	- Map layer 2&#58; interior view foreground
#	- Map layer 3&#58; 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 &#40;e.g. the doorstep&#41;

#	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&#40;lookup slice&#40;sl&#58;map layer1&#41;, off&#41; #-Turns off the exterior background layer
	set slice visible&#40;lookup slice&#40;sl&#58;map layer3&#41;, off&#41; #-Turns off the exterior foreground layer
	set slice visible&#40;lookup slice&#40;sl&#58;map layer2&#41;, on&#41;	#-Turns on the interior foreground layer
end

plotscript, show exterior, begin
	set slice visible&#40;lookup slice&#40;sl&#58;map layer1&#41;, on&#41;	#-Turns on the exterior background layer
	set slice visible&#40;lookup slice&#40;sl&#58;map layer3&#41;, on&#41;	#-Turns on the exterior foreground layer
	set slice visible&#40;lookup slice&#40;sl&#58;map layer2&#41;, off&#41;	#-Turns off the interior foreground layer
end
Last edited by Foxley on Wed Sep 24, 2014 3:02 am, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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.
⊕ 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
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Actually, I think toggling the visibility of a map layer every tick would have no noticeable slowdown.

it might be seizure inducing, but it won't slow you down :)
Post Reply