chrismaltby / gb-studio

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system
https://www.gbstudio.dev
MIT License
8.47k stars 469 forks source link

If Player At Position ($Variable0,$Variable1) only work right when you go right #1535

Closed Sconvolto closed 6 days ago

Sconvolto commented 3 weeks ago

Describe the bug If Player At Position ($Variable0,$Variable1) only work right when you go right!

To Reproduce Steps to reproduce the behavior:

  1. Create a scene and put in Init Event: Store Player Position in Variables ($Variable0,$Variable1)
  2. Create a repeating event, like add in Scene Init: Attach Timer Script to Timer 1 (1 frame or any other invterval)
  3. In Timer Script, On Tick: If Player At Position ($Variable0,$Variable1)
  4. In the True event add something like $Local0=$Variable0; $Local1=$Variable1 to track the behaviour in debugger
  5. In the False (else) Event add: Store Player Position in Variables ($Variable0,$Variable1) ; Sound Effect (Beep)

Expected behavior I expected, for any player step, to hear a beep an have the local variables ($Local0, $Local1) updated to player position and to ear ONE beep. Instead, this only works when going right and sometimes down, but I hear two beeps. If I go left or up, I hear continuous beeps and the local variables does not updates. Player moves normally, global variables are updated, but the TRUE event inside the If Player At Position only occours again if you move to the right. I've tried attaching the If Player At position event in other scripts, like in the OnUpdate of an actor, and the code behave in the same way.

Platform (please complete the following information):

chrismaltby commented 2 weeks ago

Hi @Sconvolto following your instructions I was able to reproduce some weird issues like you describe. It seems the problem was in the calculation to determine "If Actor At Position", where it wasn't taking into account that the actor could be between tiles before doing the comparision

i.e. the check was roughly doing this this if ((actorX == (tileX * 8)) && ((actorY) == (tileY * 8)) {

when it should have been something closer to this if (floor(actorX / 8) == tileX) && (floor(actorY / 8) == tileY) {

I've created an updated build with this fix included which will be part of 4.1.0 when it releases. You can try the dev build early by downloading at: https://github.com/chrismaltby/gb-studio/actions/runs/10592730672 Please note though that this new build features an updated project file format so if you try it make sure to keep a backup of your project as it will be upgraded and no longer be compatible with older versions of GB Studio.

For reference this is the project I created following your instructions which now only beeps once each time the player position changes tile GitHubIssue1535.zip

Sconvolto commented 2 weeks ago

Thank you Chris, looking forward to test it as soon as possible

chrismaltby commented 6 days ago

This fix was included in the 4.1.0 release so I think this issue can be closed now :-)