Stencyl 3.4.0 is now out. Get it now!

[Solved] 2-way doors between scenes

Spikebird

  • Posts: 13
I'm working on a simple platformer with doors that lead between scenes. My idea is that when you press the down arrow while your character is in front of a door in scene 1, it will switch to scene 2 and draw the character in front of another door, which can be entered to return to the same door in scene 1. Each scene has multiple doors that lead to different doors in other scenes. How would I do this?

« Last Edit: July 20, 2015, 01:32:02 pm by Spikebird »
[ chirp chirp ]

Mineat

  • Posts: 296
How are your doors made? If they are regions or actors, make it so that they'll be known as that type and do this:

if Down is pressed:
     if x of self = between x of door or x of door + door width
             switch scene and transition for seconds
             create actor at x of nextdoor, y of nextdoor in next scene

The x and y coordinates of nextdoor may have to be tracked and typed in.

Spikebird

  • Posts: 13
I guess that would work, but I'm also looking for a way for it to automatically find the coordinates of the actor for the next door, if possible.

« Last Edit: July 19, 2015, 03:51:45 pm by Spikebird »
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
You could add a text (or a number) attribute called ID to your door behavior, a set it in the scene editor so that each door has its own unique ID.
You should also create a text (or number) attribute called Next Door.

When the player enters the door, you store the Next Door attribute in a game attribute, and switch to the appropriate level.

The new scene should have a behavior which do this:
Code: [Select]
When created
     For each actor of type Door
          if ID of actor of type = Next Door game attribute
               create Player Actor at x of actor of type, y of actor of type.

Hope it's clear!

Spikebird

  • Posts: 13
I tried doing that, but for some reason, the player character appears in front of every door in the next scene
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
That would mean that the doors all have the same ID, I guess.

But I know what I wrote in my previous post works, because I used it in one of my project.

Spikebird

  • Posts: 13
I messed around with it a bit more and found that it draws the character in front of all the doors regardless of doorID, and even doors without that behavior. Also, this is the behavior to  add to the scenes, correct? (sorry, I'm new to Stencyl)

« Last Edit: July 19, 2015, 07:00:29 pm by Spikebird »
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
The problem (I think) is the get actor value part. You are not using it correctly. In fact, is doorID an attribute of the door behavior ? 'Cause attributes are not the same as actor values.

Try the block I used in the screenshot (it's in the behavior tab in the palette). It is used to get the value of an attribute of another behavior.

Spikebird

  • Posts: 13
Everything I try causes the character to either appear in front of every door in the scene or none of them; what exactly should I enter in the door behavior?

« Last Edit: July 20, 2015, 08:12:33 am by Spikebird »
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
See the screenshots attached. I haven't tested it, so maybe I missed something, but it should work.

  • The doorID attribute is the ID of the current door. Each door must have a unique one whithin the scene. It can be a text attribute if you find it easier.
  • The blue nextdoor attribute is the ID of the door in front of which the player should appear in the next scene. It can be a text too, depending on what you chose for the previous attribute.
  • The nextscene attribute is the scene the door leads to.
  • The colliding attribute is used to determine if the player is in front of (i.e. colliding with) the door.
  • The purple nextdoor attribute is used to store the ID of the next door between the scene switching.
The scene behavior is the same as in my previous post.

Spikebird

  • Posts: 13
I entered in that exact code and door attributes, but nothing happens when the control is pressed, so I changed it a bit. However, when the next scene loads, the character doesn't appear at all, and I'm sure the doorID and nextdoor attributes are set correctly for the corresponding doors. Does this code look correct?

« Last Edit: July 20, 2015, 12:58:21 pm by Spikebird »
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
You need to put an underscore before "doorID" in the second screenshot. The reason is that you should enter the internal name of the attribute with this block. If you don't want to mistype something, you can click on the small arrow next to the field to choose the attribute you want (see screenshot).

Spikebird

  • Posts: 13
Interesting... I changed the "doorID" part to the correct internal name and it still won't create the player upon changing scenes.
[ chirp chirp ]

Natrium

  • *
  • Posts: 110
Try to place the code in a do after 1 second block. I seem to remember now (sorry about that) that it doesn't work in a when created event, because the scene has to load first. If it does work, decrease the lenght to something like 0.1 second (or less), so that it appears to happen immediatly.

Spikebird

  • Posts: 13
Adding the delay finally got it to work. Thanks!
[ chirp chirp ]