Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teleport Test Cases #1624

Closed
fmatthew5876 opened this issue Feb 8, 2019 · 16 comments

Comments

@fmatthew5876
Copy link
Contributor

commented Feb 8, 2019

Parallel events are processed in the middle of teleporting

Setup this parallel common event

OpenSaveMenu
Teleport other map
OpenSaveMenu
Loop:
  Wait 0.0s

In RPG_RT, it will save, transition out, teleport, transition in, and save again

In Player, it will save, transition out, save ❗️ , teleport, transition in

This bug occurs with parallel common events and parallel map events.

It does not occur with autostart common, autostart map, or triggered map events.

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Feb 9, 2019

Here is something even more strange

OpenSaveMenu
Teleport other map
OpenSaveMenu
OpenSaveMenu

In RPG_RT, it will save, transition in, teleport, transition out, save

In other words, despite 3 open save menu commands, the save menu is only summoned twice!

This only happens with parallel, other event types save 3 times.

This occurs for

  • OpenMenuScreen
  • OpenSaveMenu
  • OpenLoadMenu
  • Shop
  • Change Name
  • Battle (results in black screen after 2nd battle in 2k3!)

Hypothesis

Perhaps the events are supposed to run in the middle of the teleport, and so the second OpenSaveMenu triggers, it sets a flag to summon the save menu, but since we're teleporting it doesn't come up. Then we finish the teleport, process events again, and the 3rd opensavemenu command triggers, setting the flag again, and then the save menu finally appears.

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Feb 9, 2019

Here are more test cases which expose information about how the interpreter works

Setup parallel map event

Wait 0.0s
Teleport
OpenSaveMenu
CallMenu

The save menu is called

Wait 0.0s
Teleport
CallMenu
OpenSaveMenu

The menu is called

Wait 0.0s
Teleport
CallShop
ChangeName

Shop is called

Wait 0.0s
Teleport
ChangeName
CallShop

Name change menu is called

Wait 0.0s
Teleport
CallShop
Battle

Shop is called

Wait 0.0s
Teleport
Battle
CallShop

Battle is started

Setup parallel common event

Wait 0.0s
Teleport
OpenSaveMenu
CallMenu
Loop:
  Wait 0.0s

The menu is called

Wait 0.0s
Teleport
CallMenu
OpenSaveMenu

The save menu is called

Wait 0.0s
Teleport
CallShop
ChangeName

Name change was called

Wait 0.0s
Teleport
ChangeName
CallShop

Shop is called

Wait 0.0s
Teleport
CallShop
Battle

Battle is called, screen goes black afterwards ❗️

Wait 0.0s
Teleport
Battle
CallShop

Battle is called, and then shop!

Result

For map events, the first action happens.

For common events, the second action happens. Except when the first action is a battle, then both happen

Conclusion

For the map event case, the first action is called during the frame in the middle of the teleport before it finishes. The flag is set but we're teleporting so the scene is not called. Then we teleport and the remainder of the map parallel event gets cancelled.

In the common event case, the first action is called during the frame in the middle of the teleport before it finishes. The flag is set but we're teleporting so the scene is not called. Then we teleport and process the next action, and flag gets overwritten and the first is ignored.

All the menu scenes are not allowed to start during teleport. There appears to be an exception for battles, as they can be called during teleport as we saw in the battle, shop case.

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Feb 9, 2019

Here is something more telling

Wait 0.0s
Teleport
OpenSaveMenu
SetVariable
OpenSaveMenu
Loop:
  Wait 0.0s

In this case we call save menu twice!

Hypothesis

The interpreter checks the "call menu" variable every tick of the interpreter. In the case where we do save, something, save, iterating over any event command in between the 2 menu calls gives the interpreter a chance to call the menu.

In the save, save case, the interpreter never gets a chance to summon the menu, so the first call gets overwritten by the second.

Also to confirm, with this:

Wait 0.0s
Teleport
SetVariable 1: map id
OpenSaveMenu
SetVariable2: map id
OpenSaveMenu
Loop:
  Wait 0.0s

The first set variable is the first map id, the second variable is the second map id. So this single mid teleport frame happens before we change maps.

@fmatthew5876 fmatthew5876 changed the title Parallel events processed in middle of teleport Menus called mid teleport from parallel events Feb 9, 2019

@CherryDT

This comment has been minimized.

Copy link

commented Mar 5, 2019

I believe it's because of this (from my description here):

Note that there is one additional special case: The first three items of this list (processed flag getting reset, main update methods for common events and then map events are run) are also executed when a teleport has just been executed (right after the position of the party was updated) or from inside the menu scene when a teleport/escape was executed, right before the screen fades in.

In case of the save menu being opened twice even though there are 3 save menu commands, I believe it's because the teleport is scheduled, then executed at the next frame, then this special case executes which changes the scene to the save menu (which does not yet have any effect), then the normal event processing runs, but due to the behavior described here it will run one more command from the parallel event, once more setting the current scene to the save menu. Then, at the next frame, the save menu will come up.

So, a teleport causes the event workers to run twice in the same "frame", once before the screen fades in and once afterwards ("frame" in quotemarks because the fade-in of course takes several graphical frames, however all happens in the same iteration of the game's main loop, and the frame counter is not incremented in between).

(Actually, it may even have some effects on movement, because it's actually the main update methods of the events which run, and that one does more than just calling the event worker.)

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 5, 2019

So, a teleport causes the event workers to run twice in the same "frame", once before the screen fades in and once afterwards ("frame" in quotemarks because the fade-in of course takes several graphical frames, however all happens in the same iteration of the game's main loop, and the frame counter is not incremented in between).

Is this also the case for a new game? When you start a new game you get this "only event workers" behavior running before transition in. Does RPG_RT not increment the frame counter here too?

@CherryDT

This comment has been minimized.

Copy link

commented Mar 5, 2019

Hm yes I think so, since it's all inside the map's update method, never reaching the main loop again in between

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 1 - Some teleport map cases

  1. On Map1, setup EV01 as parallel with
TeleportPlayer Map 2

On Map 2, setup EV02 as parallel with

Loop:
  OpenSaveMenu
Save map_id stop count processed
1 2 0 0
2 2 1 1
3 2 2 1

Result: Game starts immediately on Map2, then does preupdate, and update.

  1. Change Map1 EV01 to autostart
TeleportPlayer Map 2
Save map_id stop count processed current command
1 2 1 1 1
2 2 1 1 0
3 2 2 1 0

Result:

  • Map1 update - player updates
  • Autostart runs - do teleport
  • Map2 preupdate - player does not update
  • Map2 update - player updates
  1. Change Map1 EV01 to autostart
OpenSaveMenu
Transfer to Map2
Save map_id stop count processed current command
1 1 1 1 1
2 2 1 1 2
3 2 1 1 0
4 2 2 1 0

Result:

  • Map1 update runs - player updates
  • Autostart Save1
  • Map1 update runs - player blocked by autostart
  • Autostart teleport
  • Map2 preupdate - save2
  • Map2 update runs - player blocked by foreground event (curent_command == 2)
  • Map2 autostart runs - current_command cleared
  • Save3
  • Map2 update - player updates
  • Save4

Result:

  1. Change Map1 EV01 to parallel
OpenSaveMenu
SetMoveRoute: Player, Turn Right
Teleport Map2
Save map_id stop count processed current command direction
1 1 0 0 0 2
2 2 1 1 0 1
3 2 2 1 0 1

Result:

  • PreUpdate runs - player not updated
  • Save 1
  • MoveRoute set on player
  • Teleport scheduled by parallel event
  • Player updates stop_count = 1, direction=1
  • Teleport activates
  • Map2 Preupdate runs - player not updated
  • Save2
  • Player updates stop_count=2
  • Save3
  1. Change Map1 EV01 to autostart
SetMoveRoute: Player, Wait
OpenSaveMenu
Transfer to Map2
Save map_id stop count processed current command
1 1 65535 1 2
2 2 1 1 3
3 2 2 1 0
4 2 3 1 0

Result:

  • Map1 preupdate runs
  • Player updates
  • Autostart runs - set move route on player stop_count=65535, Save1
  • Player updates stop_count=1
  • Autostart runs - do teleport
  • Map2 pre update - player not updated
  • Save2
  • Map2 update - player update blocked by foreground event
  • Autostart - event cleared
  • Save3
  • Map3 update - player updates stopcount from 1 to 3??
  1. Change Map1 EV01 to parallel
OpenSaveMenu
OpenSaveMenu
Transfer to Map2
Save map_id stop count processed current command
1 1 0 0 1
2 1 1 1 2
3 2 2 1 0
4 2 3 1 0

Conclusions:

  • Teleport from parallel gets scheduled at the end of the frame, allowing player to update before teleport happens
  • Teleport from autostart happens after player, so goes immediately
@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 2 - Teleport to same map

  1. Setup EV01 as parallel
OpenSaveMenu
Teleport to this map
OpenSaveMenu
OpenSaveMenu
Save stop count processed
1 0 0
2 1 1
3 3 1

Result:

  • Preupdate
  • Save1
  • Teleport scheduled, save scheduled
  • Player updates
  • Teleport happens
  • Preupdate - save scheduled again, overwrites first!
  • Save2
  • Event starts over
  • Player updates
  • Event runs, schedules save
  • Player updates
  • Save3
  1. Setup EV01 page 1 as autostart
OpenSaveMenu
Enable Sw1
Teleport this map

Setup EV01 page 2 activated by SW1, as parallel

Loop:
  OpenSaveMenu
Save stop count processed current command
1 1 1 1
2 1 1 3
3 1 1 0
4 2 1 0

Result:

  • Player updates
  • Autostart Save1
  • Player update blocked by autostart
  • Autostart SW1 oN
  • Autostart Teleports
  • Preupdate
  • Save2
  • Player update blocked by foreground event
  • Save3
  • Player updates
  • Save4

Conclusion

Preupdate happens for self teleport

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 3 - Escape / Teleport Spell

  1. Setup Map1 EV01 as parallel:
Set Teleport point: Map2
Set Escape Location: Map2
OpenMainMenu

Setup Map2 EV01 as parallel:

Loop:
  OpenSaveMenu

In the main menu, save, and the cast Escape

Save map id stop count processed
1 1 0 0
2 2 0 0
3 2 1 1
  1. Repeat the same, except this time cast Teleport

Results: Same as above

  1. Setup Map1 EV01 as parallel:
Set Teleport point: Map1
Set Escape Location: Map1
OpenMainMenu
Loop:
  OpenSaveMenu

In the main menu, save, and the cast Escape

Save map id stop count processed
1 1 0 0
2 2 0 0
3 2 1 1
  1. Repeat the same, except this time cast Teleport

Results: Same as above

  1. Repeat the same, but just save and exit the menu without casting anything
Save map id stop count processed
1 1 0 0
2 2 1 1
3 2 2 1

Conclusion:

Casting teleport or escape always causes a preupdate to occur

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 4 - Teleport and menu conflict

  1. Setup EV01 as parallel with
OpenSaveMenu

Setup EV02 as parallel with

Teleport map2

Result: Player starts on map2, save menu is called.

  1. Setup EV01 as parallel with
Wait 0.0s
OpenSaveMenu

Setup EV02 as parallel with

Wait 0.0s
Teleport map2

Result: Player starts on map1, transition in, Teleports to map2, save menu is called.

  1. Setup EV01 as parallel with
Wait 0.0s
Teleport map2

Setup EV02 as parallel with

Wait 0.0s
OpenSaveMenu

Result: Player starts on map1, transition in, Teleports to map2, save menu is called.

Conclusion:

Scene calling flags are saved and executed on next map during its preupdate.

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 5 - Multiple teleports requested

  1. Setup EV01 parallel
Teleport to map 2

Setup EV02 parallel

Teleport to map 3

Result: Player starts on map 3

  1. Setup EV01 parallel
Teleport to map 3

Setup EV02 parallel

Teleport to map 2

Result: Player starts on map 2

  1. Setup EV01 parallel
Wait 0.0s
Teleport to map 3

Setup EV02 parallel

Wait 0.0s
Teleport to map 2

Result: Player starts on map 1, transition in, teleports to map 2

  1. Setup EV01 parallel
Wait 0.0s
Teleport to map 2

Setup EV02 parallel

Wait 0.0s
Teleport to map 3

Result: Player starts on map 1, transition in, teleports to map 3

Conclusion

Teleport works like scene calling. There is one "teleport target" variable and if multiple teleports happen on the same frame, the last one overwrites the previous and wins.

@fmatthew5876 fmatthew5876 changed the title Menus called mid teleport from parallel events Teleport Test Cases Mar 12, 2019

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 6 - Move to variable location edge cases

  1. Try move to variable location (0, 0, 0)

Result: Invalid map id error

  1. Try move to variable location (-1,0,0)

Result: Cannot open Map-0001.lmu ❗️

  1. Try to move to (1,-1,8)

Result: Player is stuck at -1 position. The rightmost 8 pixels of player sprite are visible. The player can turn via arrow keys but can't move unless you use Ctrl to force through.

  1. Setup EV01 as parallel with this code
Set Airship to player
GetOnVehicle
Wait 1.0s
Var1 = 1
Var2 = -1
Var3 = 8
MoveToVariableLocation(v1,v2,v3)
EraseEvent

Result: airship is in -1 location, but can freely move right to get back onto the map.

  1. Setup EV01 as parallel with this code
Set Boat to infront of player
GetOnVehicle
Wait 1.0s
Var1 = 1
Var2 = -1
Var3 = 8
MoveToVariableLocation(v1,v2,v3)
EraseEvent

Set leftmost tiles to water

Result: boat is in -1 location, but can freely move right to get back onto the map.

  1. Setup EV01 as parallel
Wait 0.0s
MoveToVariableLocation(v1,v2,v3)

Setup EV02 as parallel

Wait 0.0s
Teleport Map2

Result: Fades into map 1, teleports to map2.

The check for invalid map id is not done until the teleport actually occurs. In this case the bad teleport to map0 was overwritten by the teleport to map2.

Conclusion:

Since mapid 0 and -1 trigger an action. The target teleport variable must have 4 values:

  • active flag
  • mapid
  • x
  • y

Other things:

  • Player does self collision check against invalid map (x,y)
  • Vehicles don't do self collision checks against invalid map (x,y)
@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 7 - Test event code after teleport

  1. Setup EV01 as parallel
Teleport Map2
Teleport Map3
Sw1

Result: New game starts on map3, Sw1 is on before fade in

  1. Change EV02 as autostart

Result:
Transition in Map1, Teleport map2, Teleport map3, Sw1 on after transition in

Conclusion

Parallel events continue running code after a teleport. Autostart does not.

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2019

Test Cases 8 - What about areas?

  1. Create Map1, and an area Map2 inside of Map1

Use MoveToVariableLocation to go to map2

Result: Cannot load map0002.lmu

Conclusion

You can't teleport to area maps.

@CherryDT

This comment has been minimized.

Copy link

commented Mar 12, 2019

Which brings up an interesting question.
What would happen when we create such a file?

After all, the entry exists in the map tree data structure.

I wonder what kind of effect that would have. It would be something that I'd imagine people to start using as a way of "obfuscation" or "copy protection"... :D (Because when looking at that map in RM you would see the area and not the real map...)

Furthermore, your Map-0001.lmu made me also curious, why -1 is accepted as map ID, there is no map tree entry for it, I thought... or maybe there is, and it's the project root? I don't remember. Same thing, one could create such a file...

@carstene1ns carstene1ns added this to the 0.6.1 milestone Mar 13, 2019

@fmatthew5876

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2019

Test Cases 9 - Teleport and move routes

  1. Setup Map1 EV01 as autostart
SetMoveRoute: Player, Up
Wait 0.0s
Wait 0.0s
Wait 0.0s
OpenSaveMenu
Transfer Map 2

Setup Map2 EV02 as parallel

Loop:
  OpenSaveMenu
Save map id remaining step stop count move route overwrite move route index current command
1 1 160 1 1 1 5
2 2 0 0 1 1 6
3 2 0 1 0 1 0

Result:

  • Save1
  • remaining_step goes to 0 during the teleport
  • Preupdate - nothing happens to player
  • Save2
  • Player updates, finishes move route
  • Old autostart event finishes - current_command -> 0
  • Save 3
  1. Change Map2 EV02 to autostart
Save map id remaining step stop count move route overwrite move route index current command
1 1 160 1 1 1 5
2 2 0 0 1 1 2
3 2 0 1 0 1 2

Result:

  • Save1
  • remaining_step goes to 0 during the teleport
  • Preupdate - nothing happens to player
  • Player updates -not finish move route??
  • Old map1 autostart event finishes current_command -> 0
  • New map2 autostart begins current_command -> 2
  • Save2
  • Player updates, finishes move route
  • Save 3
@fmatthew5876 fmatthew5876 referenced this issue Mar 14, 2019
1 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.