What is wrong with this code???
Blitz3D Forums/Blitz3D Beginners Area/What is wrong with this code???
| ||
Function LoadLogo() Logo_Pointer = LoadImage ("logo.png") If (Logo_Pointer) <> 0 Then QuickExit Else RuntimeError "Failed to find & load required image file" End If .QuickExit End Function I keep getting "ELSE without IF" ??????? |
| ||
try this: Function LoadLogo() Logo_Pointer = LoadImage ("logo.png") If (Logo_Pointer) <> 0 goto QuickExit Else RuntimeError "Failed to find & load required image file" End If .QuickExit End Function See if that works :) DeViL |
| ||
it does not work ... |
| ||
Hmmm, are you still getting that message "Else without EndIf"? |
| ||
Loading an image inside a function will not make it available to the rest of the code, as variables used within functions are local unless set as globals prior to calling the function. I suggest you do something similar to the following code, which will allow you to specify a filename and decide which variable will be the handle of the image. Also, when making functions, try and make them as flexible as possible so that they can be reused. This will allow you to have less code but maintain usability. Like with the above function, you can use it to load and test as many images you want, but with the code in the top of this thread, you are limited to just loading one image into one variable without any flexibility. Coding with flexibility and reuse in mind will speed up future coding projects as function modules can be reused and doesn't have to be coded from scratch. [edit: added the above text] |
| ||
you example above works, @Devil. THANKS I did not have the "goto" command, I thought Blitz could "jump to" a local label by just having the labelname and no "goto" you solved my problem. Thanks |
| ||
And by the way, I always use GLOBAL pointers :-) |
| ||
From your original code, instead of this:Then QuickExit ...you could have said: Then Return |
| ||
@soja "RETURN" ??? where does that command come from? and where does it return? I assume it equels exiting the function? *** EDIT *** ah, just checked the DOCS for the RETURN command. It all makes sense now. Thanks @Soja |
| ||
This:Function LoadLogo() Logo_Pointer = LoadImage ("logo.png") If (Logo_Pointer) <> 0 Then QuickExit Else RuntimeError "Failed to find & load required image file" End If .QuickExit End Functioncan all be simplified to this: Function LoadLogo() Logo_Pointer = LoadImage ("logo.png") If Logo_Pointer = 0 Then RuntimeError "Failed to find & load required image file" End Function |
| ||
@WolRon Thanks for your version :-) |
| ||
By the way, I think the correct closing of the IF-ELSE- nest is not "End If" (two words) but "EndIf" (one word). |
| ||
@Sir Gak According to the documentation, "End If" and "EndIf" are 100% the same. BlitzSupport?? |
| ||
EndIf and End If function the same. |
| ||
@Noel Thanks for clarifying this |