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

ENDLOOP immediately followed by STARTLOOP does not show in debug rules display #1048

Open
david-pfx opened this issue Feb 9, 2025 · 6 comments

Comments

@david-pfx
Copy link
Contributor

startloop
[ > p | g | ] -> [ | > p | > g ]
endloop
startloop
[ > p | b ] -> [ p | g ]
endloop

shows as

STARTLOOP
  (53) DOWN [ | g | up player ] -> [ up g | up player | ]
+ (53) DOWN [ down player | g | ] -> [ | down player | down g ]
+ (53) RIGHT [ | g | left player ] -> [ left g | left player | ]
+ (53) RIGHT [ right player | g | ] -> [ | right player | right g ]
STARTLOOP
  (56) DOWN [ b | up player ] -> [ g | player ]
+ (56) DOWN [ down player | b ] -> [ player | g ]
+ (56) RIGHT [ b | left player ] -> [ g | player ]
+ (56) RIGHT [ right player | b ] -> [ player | g ]
ENDLOOP

But it seems to work OK.

@increpare
Copy link
Owner

good catch - thanks!

@david-pfx
Copy link
Contributor Author

So now

STARTLOOP
ENDLOOP

will not show the ENDLOOP? I guess that's less of an issue.

@increpare
Copy link
Owner

oh there's still an issue

https://www.puzzlescript.net/editor.html?hack=a0e8e9bbf8208c98a036705c5d6b88a5

startloop
endloop

[ > Player | Crate ] -> [ > Player | > Crate ] 

shows (incorrectly, i think?)

Rule Assembly : (4 rules)
===========
STARTLOOP
  (84) DOWN [ crate | up player ] -> [ up crate | up player ]
ENDLOOP
+ (84) DOWN [ down player | crate ] -> [ down player | down crate ]
+ (84) RIGHT [ crate | left player ] -> [ left crate | left player ]
+ (84) RIGHT [ right player | crate ] -> [ right player | right crate ]
===========

it's probably just visual..i guess i'll have to try understand it properly...

@increpare increpare reopened this Feb 10, 2025
@david-pfx
Copy link
Contributor Author

Here's my suggestion:

       while (loopIndex < state.loops.length) {
            const loop = state.loops[loopIndex];
            if (loop[0] < rule.lineNumber) {
                if (loop[1] == 1) {
                    output += subrtext + "STARTLOOP<br>";
                    subrtext = '';
                } else output += "ENDLOOP<br>";
            } else break;
            loopIndex++;
        }

and after the loop:

    if (loopIndex < state.loops.length)
        output += "ENDLOOP<br>";

@david-pfx
Copy link
Contributor Author

I think there's more trouble. In my testing the construct

STARTLOOP
[  some rule ] -> [ some rule ]
ENDLOOP
STARTLOOP
late [  some rule ] -> [ some rule ]
ENDLOOP

fails to loop, because the second (LATE) loop looks empty, and the second ENDLOOP overrides the first.

I'd like to fix it but right now I'm not sure how (other than a rewrite of that code).

@david-pfx
Copy link
Contributor Author

Here's the fix, in generateLoopPoints:

                if (firstRuleLine >= loop[0]) {     //@@
                    source = i - 1;
                    // this test can fail if there are no rules between startloop and endloop, either way
                    if (source >= target)
                        loopPoint[source] = target;
                    outside = true;
                    break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants