AmiBlitz3
AmiBlitz3 copied to clipboard
Possible Bug in compiler check with "If..else"
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?
I'm not a dev, just a user. This is what i think is happening:
-
You did not write "elseif" and there is no elseif in Amiblitz. There is if and else.
-
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.
- 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:
- there is no condition as part of "else"
- 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
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
Works as aspected - nevertheless "ElseIf" would be a nice improvement.