error 'else' without 'if'
Blitz3D Forums/Blitz3D Beginners Area/error 'else' without 'if'
| ||
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 |
| ||
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) |
| ||
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 |
| ||
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. |
| ||
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 |
| ||
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) |
| ||
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. |