Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
ncrecc
Posts: 153
Joined: Thu Jul 12, 2018 12:59 am

Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by ncrecc »

https://i.frogbox.es/lf7
^ Here's a tape of Level 6, "Starships", in Niko Boehm's tutorial (which is preincluded with most downloads of RnD). I was investigating score corruption and decided to make a high-score tape of it using good ol' single-step mode. When I recorded it, it worked perfectly - I collected all gems and made it out of the exit for a rather good score of 337. But after watching it again, I noticed something was wrong: a gem that I had TAS snapped at while I was recording the tape was not collected at all when I watched the tape again.
Image
(That erratic movement you see against the amoeba from 00:03 to 00:05 is intentional, it was just a little key tapping so I could wait for the spaceship to explode.)
After rewatching my tape several times, I think I see the problem now: when I snapped at the falling gem at 00:05, it was supposed to be immediately followed by snapping the other gem that fell right after it as well. Since the tape did not save this, I completely miss one of the gems when the tape is played back, since the positions of the gems were entirely different due to that falling gem not being collected.
Anonycat
Posts: 47
Joined: Thu Mar 27, 2008 4:45 am

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by Anonycat »

If you want your tapes to sync, you have to insert at least a 1-frame pause after you snap in some direction, before you're allowed to snap again. Unlike the case of flicking a conveyor belt, this wait doesn't have to be with a completely blank 0x00 input, so just tapping the snap key by itself for a 0x10 is good enough here.

In your case, you wouldn't even have to worry about that desync pattern or inserting a 1-frame wait if, after you walked right when the path of falling gems was clear, you had snapped DOWN before moving up to fetch the top gem. Or you could score even higher, at the cost of a few seconds, by doing this.
Attachments
006.score.tape
(236 Bytes) Downloaded 186 times
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by Holger »

First of all, thanks a lot for this bug report -- I was able to reproduce this bug yesterday, and I think this category of bugs is one of the worst bugs that may happen: Recording and solving a level, but then having a tape that replays slightly different, causing the game to fail instead of solving the level.

The most important information was that you used single-step mode when you encountered this bug, and in fact, this bug only occurs in single-step mode, but not when playing normally. I never observed this odd behaviour by myself at all so far, and it only happens in some special situations (when continuously snapping at the same field). (It happens with both TAS snapping and normal snapping, by the way.)

The cause of the problem was that, when using single-step mode, key release events after snapping caused snapping to be "stopped" (so it can happen again in the next frame), and pressing those keys for snapping again in the next frame caused another snap action to be executed. This is wrong, because technically those keys were never released from the game engine's point of view (because they were recognized as "pressed" in all subsequent game frames, even though the keys were physically released when playing in single-step mode). So, this has to be fixed to take into account that snapping twice requires a "non-snapping" key input for at least one frame. In single-step mode, this can be accomplished by pressing and releasing the snap key once (without pressing a direction key), which enters a "no snapping" action for one frame, ending a previous snap action and allowing for the next snap action in the next game engine frame. (This "feels" a bit wrong when playing in single-step mode, as key presses/releases differ from what one would do in non-single-step mode, but it is the only way to enter those "non-snap" actions in between subsequent snap actions required to make it work like in normal mode.)

Anonycat has also described this in the above post, and although the proposed workaround will work fine, this has to be fixed, of course, so that any recorded tape action will always result in a played tape action with the exact same result as when recording the tape.

This bug will be fixed in the next release version.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by filbo »

I'm a little worried that a fix for this may cause some previously working tapes to stop working. But of course you will be watching out for that so I should probably suppress that worry.

I also have a wish, that the engine would somehow be able to detect old tapes made with this flaw and be able to 'upgrade' them to work. That is: I have a number of saved tapes which don't play back successfully, and expect that some are due to this issue.

Perhaps an external program or --exec flag to RnD could parse tapes for this and emit a 'fixed' tape? Then a script could run through tapes and basically do:

if [ tape does not complete successfully ] {
... create 'fixed 'tape
... if [ fixed tape does complete successfully ] {
...... replace original with fixed tape
... }
}
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by BryanFRitt »

if [ tape does not complete successfully ] {
... create 'fixed 'tape
... if [ fixed tape does complete successfully ] {
...... replace original with fixed tape
... }
}
I'm a little worried that a fix for this may cause some previously working tapes to stop working.
?Instead of just 'replace' do a backup first?
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by filbo »

Sure, that would be good practice.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by Holger »

I'm a little worried that a fix for this may cause some previously working tapes to stop working.
That should be technically impossible, as the bugfix does not change how existing tapes are played, but only how new tapes are created.
But of course you will be watching out for that so I should probably suppress that worry.
Yes, I ran my tape test suite after the fix, and the results were the same as before. :-)
I also have a wish, that the engine would somehow be able to detect old tapes made with this flaw and be able to 'upgrade' them to work. That is: I have a number of saved tapes which don't play back successfully, and expect that some are due to this issue.
That may be true, but unfortunately, this kind of problem is impossibe to be fixed afterwards, because there is no way to determine at which frame of the recorded tape actions the "stop snapping" actions would have to be inserted.

For example, I have played a test level in single-step mode with repeated snap actions that solve the level, but result in a broken tape due to the problem described here. Here's a dump of that tape:

Code: Select all

------------------------------------------------------------------------------- 
0000: 0:00 [    |  ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00000]          
0001: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (098) [00001]          
0002: 0:00 [    |  ] - 1:00 [    |  ] - 3:00 [    |  ] - (078) [00099]          
------------------------------------------------------------------------------- 
As you can see, there is a long row of continuous snapping input actions (for 98 frames), and there is no chance to find out at which frames a falling gem was snapped.

After the fix, doing multiple snap actions in single-step mode like before does not work anymore, because the keys for snapping are correctly recognized as "always pressed" by the game engine now; to perform multiple snap actions, the snap key has to be released in a way that the game engine "sees" a non-snapping action for at least one frame. The corresponding tape to solve the level again now looks like this:

Code: Select all

------------------------------------------------------------------------------- 
0000: 0:00 [    |  ] - 1:00 [    |  ] - 3:00 [    |  ] - (025) [00000]          
0001: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00025]          
0002: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00027]          
0003: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00028]          
0004: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00029]          
0005: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00031]          
0006: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00032]          
0007: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00034]          
0008: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (003) [00036]          
0009: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (003) [00039]          
0010: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00042]          
0011: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00044]          
0012: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00046]          
0013: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00048]          
0014: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00049]          
0015: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00051]          
0016: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00053]          
0017: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00055]          
0018: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00056]          
0019: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00058]          
0020: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00060]          
0021: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00061]          
0022: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00063]          
0023: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00065]          
0024: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00067]          
0025: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00068]          
0026: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00070]          
0027: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (001) [00072]          
0028: 0:12 [ >  |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00073]          
0029: 0:10 [    |1 ] - 1:00 [    |  ] - 3:00 [    |  ] - (002) [00075]          
0030: 0:00 [    |  ] - 1:00 [    |  ] - 3:00 [    |  ] - (005) [00077]          
------------------------------------------------------------------------------- 
As can be seen, these snap actions have to be interrupted by a non-snapping input action for at least one frame (where the snap key is still pressed here, but the "right direction" action was released for at least one frame, so a new snap action is started when that key is pressed again).
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by filbo »

Just checking,

In the description of the new tape, you're saying that the game inserted into the tape stream periodic 'release' actions, right? Not that the player had to change his keyboard actions?

I very often consume huge piles of falling gems by standing next to the bottom (where they become still) and holding down ctrl-left arrow or whatever. Would not want to have to change that to 'ctrl-left-left-left-left...'
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by Holger »

In the description of the new tape, you're saying that the game inserted into the tape stream periodic 'release' actions, right? Not that the player had to change his keyboard actions?
No, I think that I did not say this. What I said was the following:
to perform multiple snap actions, the snap key has to be released in a way that the game engine "sees" a non-snapping action for at least one frame
So the game does not insert anything that was not performed by the player -- it inserts exactly what the player entered via the configured input device. Especially it does not insert any "release" actions (not in the old version and not in the new version of the code).

What the game did in the old version: It performed actions as if the snapping was interrupted for at least one frame, although such actions were not entered (but only seemed to be enterend due to single-step mode). As those actions were never entered, they were not in the tape, so replaying it failed.
I very often consume huge piles of falling gems by standing next to the bottom (where they become still) and holding down ctrl-left arrow or whatever. Would not want to have to change that to 'ctrl-left-left-left-left...'
Are you speaking of normal playing here or of single-step mode? (I think this is non-single-step mode now.)

Could you please provide me with a simple level demonstrating this? I stumbled upon this while analyzing the above problem, and found out that "continuous snapping" apparently stopped working a long time ago (although it worked once). There's an option in the player setting, and it is enabled by default, but apparently it does not work anymore.

So may it be possible that you are speaking of very old levels that you played with such "continuous snapping" behaviour? Or are you able to reproduce this with a newly created level (with a recent 4.x version of the game)?

I would like to fix this, as it seems that the checkbox "continuous snapping" does not have any effect anymore (or I may have missed something)... :?
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by Holger »

Could you please provide me with a simple level demonstrating this? I stumbled upon this while analyzing the above problem, and found out that "continuous snapping" apparently stopped working a long time ago (although it worked once). There's an option in the player setting, and it is enabled by default, but apparently it does not work anymore.
Sorry, please forget what I've written here -- I was just able to reproduce that "continuous snapping" with a newly created level. I have no idea what I did a few days ago when I was not able to snap several gems with just the snap key and direction key held pressed once (just as it should be with that setting enabled). I'll investigate some more...

Update: OK, I've just found out what the problem was -- I tried to continuously snap gems while they are falling (i.e., they had an empty space below them), which indeed does not work even with "[x] continuous snapping" enabled. Continuously snapping them after they have "landed" (with more of them falling down from above) indeed works just as it should.

That said, the problem initially described in this thread does not happen even with single-step mode when snapping gems that do not fall, but it happens only when snapping gems in single-step mode while they are falling down. That's also the reason why this (now fixed) "broken tape" problem should not have been occured that often...
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: Snapping (or is it just TAS snapping?) at falling gems may not save correctly in tapes

Post by filbo »

Sorry, I do think I misspoke. I was talking about continuous snapping in non-single-step mode, totally irrelevant to this discussion. Was not aware of the setting to allow continuous snapping in single step mode.
Post Reply