AmiBlitz3 icon indicating copy to clipboard operation
AmiBlitz3 copied to clipboard

Possible Bug in compiler check with "If..else"

Open Nju79 opened this issue 3 years ago • 2 comments

Following code give me no compiler error and changes the variable to the value -1:

MyFixedVariable.b = 1
If MyFixedVariable = 3
  Print MyFixedVariable ;will never jump in, that's correct
else MyFixedVariable < 3 ;is changing the value to -1
  Print MyFixedVariable ;printing out -1
EndIf

This should a be bug, shouldn't?

Nju79 avatar Sep 22 '21 09:09 Nju79

I'm not a dev, just a user. This is what i think is happening:

  1. You did not write "elseif" and there is no elseif in Amiblitz. There is if and else.

  2. else does not have a condition as part of it.

you wrote:

  if ...
    do something
  else MyFixedVariable < 3
    ...
  endIf

which translates to

  if ...
    do something
  else
    MyFixedVariable < 3
    ...
  endIf

which IMHO translates in Amiblitz to

  if ...
    do something
  else
    MyFixedVariable = (MyFixedVariable < 3)      ;*
    ...
  endIf

*Note that the right term in this line is true and true has a value of -1 in Amiblitz.

  1. because:

in Amiblitz you can write x+1 instead of x=x+1

for example:

  if ...
    do something
  else MyFixedVariable +1
    ...
  endIf

would increase the variable by one if the else branch is executed.

so in short:

  1. there is no condition as part of "else"
  2. the syntax you use alters the contents of the variable. and the result of the term is true, which is expressed as "-1"

Hope this helps Stefan

stevetronic avatar Sep 25 '21 22:09 stevetronic

Thank you for your explanation. Why does the following program code work and why does it write "5" as output?

MyFixedVariable.b = 5
If MyFixedVariable +1
  Print MyFixedVariable
else MyFixedVariable +2
  Print MyFixedVariable
EndIf

Nju79 avatar Sep 26 '21 10:09 Nju79

Works as aspected - nevertheless "ElseIf" would be a nice improvement.

honitos avatar Sep 14 '22 11:09 honitos