Discussion

This code crashes the app on iOS

1

Jeanmilost 2020-02-16 18:47

Hello, just a simple bug report. The below code crashes the app on iOS:
IF BALLX <= LIMITLEFT THEN
BALLX = LIMITLEFT
OFFSETX = -OFFSETX
ELSE
IF BALLX >= LIMITRIGHT THEN
BALLX = LIMITRIGHT
OFFSETX = -OFFSETX
END IF

The cause is due to the ELSE IF split on 2 lines, because when I put the both instructions on the same line, all is fine and the crash no longer happens.


was8bit 2020-02-17 05:08

... it isn't a bug, your syntax is incorrect...

When you begin a line with IF it requires a following line that begins with END IF

Count how many lines begin with IF.. you have 2... therefore it requires 2 following lines that begin with END IF

now, count how many lines you have that begin with END IF...you only have 1 when it is expecting 2... not a bug, have to have correct syntax...

Here it is with the correct syntax...

IF BALLX <= LIMITLEFT THEN
BALLX = LIMITLEFT
OFFSETX = -OFFSETX
ELSE
IF BALLX >= LIMITRIGHT THEN
BALLX = LIMITRIGHT
OFFSETX = -OFFSETX
END IF
END IF


was8bit 2020-02-17 05:12

It can get confusing... here are some examples....

Stack em all into one line...

IF 1=1 THEN PRINT "1" ELSE IF 2=2 THEN PRINT "2" ELSE PRINT "3"


was8bit 2020-02-17 05:14

.... or spread them out across multiple lines...

IF 1=1 THEN
PRINT "1"
ELSE IF 2=2 THEN
PRINT "2"
ELSE
PRINT "3"
END IF


was8bit 2020-02-17 05:19

Layer stacked conditionals inside of a spread out conditional...

GAMEPAD 1
DO
IF UP(0) THEN
IF BUTTON(0,0) THEN PRINT "UA" ELSE IF BUTTON(0,1) THEN PRINT "UB" ELSE PRINT "U"
ELSE IF DOWN(0) THEN
IF BUTTON(0,0) THEN PRINT "DA" ELSE IF BUTTON(0,1) THEN PRINT "DB" ELSE PRINT "D"
END IF
WAIT VBL
LOOP


was8bit 2020-02-17 05:21

Or layer spread out conditionals inside of a single spread out conditional...

GAMEPAD 1
DO
IF UP(0) THEN
IF BUTTON(0,0) THEN
PRINT "UA"
ELSE IF BUTTON(0,1) THEN
PRINT "UB"
ELSE
PRINT "U"
END IF
ELSE IF DOWN(0) THEN
IF BUTTON(0,0) THEN
PRINT "DA"
ELSE IF BUTTON(0,1) THEN
PRINT "DB"
ELSE
PRINT "D"
END IF
END IF
WAIT VBL
LOOP


was8bit 2020-02-17 05:26

Notice that conditionals stacked into one line do NOT use an END IF statement...

And also note that all conditionals spread out across several lines MUST have a matching END IF for every beginning IF

I indent my text such that each matching pair lines up...

IF
END IF

DO
LOOP

FOR I
NEXT I

WHILE
WEND

The text between them gets indented to the right so I can be sure everything requiring a match has a match...


was8bit 2020-02-17 05:37

Here is a VERY layered set of conditionals!!

PULSE=0
GAMEPAD 1
DO
IF UP(0) THEN
IF BUTTON(0,0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "UA"
END IF
ELSE IF BUTTON(0,1) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "UB"
END IF
ELSE
IF LEFT(0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "LU-"
END IF
ELSE IF RIGHT(0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "-UR"
END IF
ELSE
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "-U-"
END IF
END IF
END IF
ELSE IF DOWN(0) THEN
IF BUTTON(0,0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "DA"
END IF
ELSE IF BUTTON(0,1) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "DB"
END IF
ELSE
IF LEFT(0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "LD-"
END IF
ELSE IF RIGHT(0) THEN
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "-DR"
END IF
ELSE
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT "-D-"
END IF
END IF
END IF
ELSE
IF PULSE=0 THEN
PRINT "-----------"
ELSE
PRINT ":"
END IF
END IF
PULSE=(PULSE+1) MOD 30
WAIT VBL
LOOP


was8bit 2020-02-17 05:39

The first layer is...

IF UP(0) THEN

ELSE IF DOWN(0) THEN

ELSE

END IF


was8bit 2020-02-17 05:41

Inside the IF UP(0)THEN is a second layer..

IF BUTTON(0,0) THEN
ELSE IF BUTTON(0,1) THEN
ELSE
END IF


was8bit 2020-02-17 05:43

And inside the ELSE is 3rd layer..

IF LEFT(0) THEN
ELSE IF RIGHT(0)THEN
ELSE
END IF


was8bit 2020-02-17 05:44

And inside the LEFT(0) is a 4th layer....

IF PULSE=0 THEN
ELSE
END IF


was8bit 2020-02-17 05:46

So, you can see, when stacking and layering your conditionals, you MUST be sure to have all matching IF with END IF accounted for ... not only to avoid errors, but also to be sure your code is behaving and doing what you intend for it to do...


was8bit 2020-02-17 05:51

The identation is viewable here:

https://lowresnx.inutilis.com/uploads/HDUnC8DetD_Quadruple_Stacked_Layered_Conditional_Example.nx


Timo 2020-02-17 07:24

Ok, this code actually crashes the App, it does not only show an error message. This should not happen, I add it to my bug list. Thanks!


Timo 2020-02-21 10:28

Issue added to the bug tracker: https://github.com/timoinutilis/lowres-nx/issues/113


was8bit 2020-02-21 10:30

And I didn't catch that it crashes without an error message, my bad :/


Log in to reply.