error 'else' without 'if'

Blitz3D Forums/Blitz3D Beginners Area/error 'else' without 'if'

Rooster(Posted 2014) [#1]
I have been getting the error 'else' without 'if' when I use the command "else" my code.
I will put the snippet below

Function PayerMove ( )
If KeyDown ( 17 ) And jumplemet <3 Then gamey =( gamey -10 )
If KeyDown ( 30 ) Then gamex =( gamex -5 )
If KeyDown ( 32 ) Then gamex =( gamex +5 )
If gamey < 290 Then gamey =( gamey + 7 )
Else jumplemet =( jumplemet +1 )
End Function

If anyone knows how to fix this please let me know.
thanks


RustyKristi(Posted 2014) [#2]
Hey Rooster,

try this code:

Function PayerMove ( )
If KeyDown ( 17 ) And jumplemet <3 Then gamey =( gamey -10 )
If KeyDown ( 30 ) Then gamex =( gamex -5 )
If KeyDown ( 32 ) Then gamex =( gamex +5 )
If gamey < 290 Then
gamey =( gamey + 7 )
Else jumplemet = ( jumplemet +1 )
End If
End Function


bring the last if then.. to another line (if that is your condition then close it with end if)

already tested this to work.


*If the above is one set of IFs then you should put elseif instead of If (except for the first If)


Who was John Galt?(Posted 2014) [#3]
A couple extra tips-
Use a code box to display code in the forum as it's easier to read. Just use the forum tags (code) and (/code) <but replace the round brackets with square ones< around your code to do it. Also, indenting with the tab key as I have below makes it easier to read in your code editor.

Function PayerMove ( )
    If KeyDown ( 17 ) And jumplemet <3 Then gamey =( gamey -10 ) 
    If KeyDown ( 30 ) Then gamex =( gamex -5 )
    If KeyDown ( 32 ) Then gamex =( gamex +5 )
    If gamey < 290 Then
         gamey =( gamey + 7 ) 
    Else
         jumplemet = ( jumplemet +1 )
    EndIf
End Function 



Zethrax(Posted 2014) [#4]
The line 'Else jumplemet =( jumplemet +1 )' has no matching 'If' command preceeding it. All the 'If' commands that come before it are single-statement 'If' 'Then' command combos that are terminated by the end of the line.


Rooster(Posted 2014) [#5]
RustyKristi, Thank you so much! That bug was frustrating for me.
I am new to programming, so I need all the help I can get ;)


John Galt
Thanks for the tips, this is my first time posting.
So I was wondering how to do that.

Thanks again for every thang


Yasha(Posted 2014) [#6]
single-statement 'If' 'Then' commands can also be terminated by a statement separator


This is false. Content after the separator will form part of the inline If, which will only be terminated by the end of the line. Try it and see. Blitz3D's syntax is inconsistent in this area - separators are not quite identical to newlines.

(best to just not stack multiple statements in a line, in a newline-sensitive language)


Zethrax(Posted 2014) [#7]
This is false. Content after the separator will form part of the inline If, which will only be terminated by the end of the line. Try it and see. Blitz3D's syntax is inconsistent in this area - separators are not quite identical to newlines.

Yes I had a bit of a brain-fart there. I've corrected my above post to avoid confusion.