Like @Blendman said this error is not caused by using a function. A function is basically much like the gosub pattern conceptually but structured differently with a more formal pattern to increase clarity.
You could load some global variables (or registers or stash values in memory addresses back in machine code days) and jump to a subroutine. The subroutine would then pull that data out... do its thing then possibly return a value by storing it in a global variable (or register in asm). Functions are just a "nicer" way of accomplishing the same thing by providing a more formal / structured interface. So instead of doing something like
x=1 : y=2: gosub SetPosition you can instead write
SetPosition(1, 2)
If you used gosub in your example you would get the same error...
do
gosub Start
Print( ScreenFPS() )
Sync()
loop
end // not needed here but added just because this shows where the main program execution ends
Start:
LoadImage ( 3, "intro/start.jpg" )
// sprite with ID of 3 will be created each time this line executes and it cannot be created if it already exists.
// It would need to be deleted first and is almost certainly not what you want.
CreateSprite ( 3, 3 )
SetSpritePosition ( 3, 0, 0 )
return
Typically as @Blendman said you want to only initialize such things (creating sprites, etc) like this one time before your loop.
If you want to have it inside the loop for some reason then the function would just need to check if the sprite already exists and only create it if it does not exist. You'd want to do the same thing for your image in this case.
function Start ( )
// only create this image from the loaded image file if image ID=3 does not already exist
if GetImageExists(3)=0 then LoadImage( 3, "intro/start.jpg" )
// only create sprite with ID=3 if it does not already exist
if GetSpriteExists(3)=0 then CreateSprite( 3, 3 )
SetSpritePosition ( 3, 0, 0 )
endfunction
and the gosub version
Start:
// only create this image from the loaded image file if image ID=3 does not already exist
if GetImageExists(3)=0 then LoadImage( 3, "intro/start.jpg" )
// only create sprite with ID=3 if it does not already exist
if GetSpriteExists(3)=0 then CreateSprite( 3, 3 )
SetSpritePosition ( 3, 0, 0 )
return
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)