You can use something like this:
// *******************************************
// *** Example of generic game structure. ***
// *******************************************
// initialization stuff below here..
// screen setup, variables declaration etc..
InitGame() // start your game things..
// main game loop..
Do // start loop. anything between Do and Loop will be repeated endlessly, unless the Exit command is called.
UpdateGame() // as it says, all your updates to the game go in this function here.
If GetRawKeyPressed(27) then Exit // Esc key (on windows of course) exits the main game loop causing the next command outside this loop to be executed.
sync() // update all the internal AGK stuff(like screen. collisions etc).
Loop
EndGameSequence() // your closing game code here, e.g. game end screen.
End // actually halts execution and ends the program..
// so this really is the bottom line.
// all code below end is read only when referenced in the code above(well, sort off) ;-)
// -------------------------------------------------------------------------------------------------------------------------
// all your functions called above go in here..
// e.g.:
Function InitGame()
// fill in yourself..
EndFunction
Function UpdateGame()
// fill in yourself..
EndFunction
Function EndGameSequence()
// fill in yourself..
EndFunction