Ydin : koodirakenteet

GOSUB


   KUVAUS

Hyppää toiseen kohtaan koodissa. Toisin kuin Goto, pääset myöhemmin palaamaan tähän hyppykohtaan RETURN-kutsulla.

Gosub-kirjanmerkkejä kutsutaan aliohjelmiksi. Aliohjelmat päättyvät aina RETURN-komentoon, joka palauttaa ohjelman sinne, mistä aliohjelmaan hypättiin. Aliohjelmat ovat siis "käy-tekemässä-jotain-ja-palaa-takaisin" -rakenteita. ÄLÄ UNOHDA RETURN-KOMENTOA! Sen puuttuminen voi kaataa ohjelman tai aiheuttaa outoja toimintahäiriöitä itse pelissä.

   KÄYTTÖ
GOSUB kirjanmerkki

Katso myös: RETURN, GOTO

   ESIMERKKI
x=200: y=150

AddText "Guide the cube via arrows"

'This is the main program. See how short it is
Repeat

    GoSub UpdateControls
    GoSub DrawAll
    
    DrawScreen

Until EscapeKey()

'End program so we can't accidentally
'access the sub-programs
End

'------------------------------------------------

UpdateControls:

    If RightKey() Then x=x+1
    If LeftKey() Then x=x-1
    If DownKey() Then y=y+1
    If UpKey() Then y=y-1

Return

'------------------------------------------------

DrawAll:

    Box x-20,y-20,40,40,OFF
    
Return

<<TAKAISIN