Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / restart command?

Author
Message
KMCE
8
Years of Service
User Offline
Joined: 8th Apr 2016
Location:
Posted: 9th Apr 2016 20:45
Is there a specific command to restart a game. Ive tried searching the command index page and cant find anything that would seem relevant to restarting the game.

Also, as a side question the compilier is not giving any errors, even when i tried putting ones in on purpose to test it, any reason why that would be
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 10th Apr 2016 02:31 Edited at: 10th Apr 2016 03:54
AGK is a Structured Programming language, so you should stick to the best practices guidelines for this style of programming. Which is to say have a top-down approach, building a 'pyramid' of functions/procedures where the deeper down you go from the top, you get more granular and specific in your code. Preferably with no lateral horizontal dependencies (messy), only vertical top to bottom dependencies (clean-ish).

This will however only put you back to the main loop (usually some kind of start menu or similar) from where you first started to dig down to other procedures. You can exit the main loop, but this will quit the program. This is due to how - as the name implies - Structural Programming relies upon control structures (various conditional loops, like while, repeat until, for next, or an exit option in a do loop structure) rather than arbitrary jump in points. You will always return to from where you branched off by calling another function. In effect, you can only make jump out points. This have the advantage that it prevents much of the messy spaghetti goto or gosub commands create, as your code should nearly by magic become hierarchical all by itself. The disadvantage is, hmm, I can't really think of any...

This diagram is pretty typical of how you should plan your code:



In a typical program, like my latest effort - a little score keeping app for a Twitch channel - the main loop code would look something like this:



It is however important to keep track of your assets - each screen you draw the needed bits and bobs, but when exiting you also need to clean it up, or else you may run into trouble. Most my 'Control Functions' consist of four distinct parts. 1: Declare local variables, 2: Draw screen, 3: Decisions loop, 4: Clean up screen. Like here from the same app:



(I like to keep track of all my dependencies, so where there are any, I collect them in a comment-box at the top of the function. That way I can easily and at a glance see what a specific function use should I make any changes. Such dependencies I strive to have less and less of - ideally none - the further down the pyramid I go. This function however is only on tier 2 of the pyramid, so there is quite a few of them. My naming convention is having brackets[] for an array, and a curlybrace{} for a data-type. discrete globals I avoid like the plague. They can easily grow too numerous to keep track of. I am also no fan of the Exit command, as it encourages multiple paths to exit a function, rather than having just the one entry point - as defined by the command 'function' - and only the one exit point - as defined by the command 'endfunction')

As for your second question, I'm not sure what to say. I can hardly type in a single line of code without having to revisit it to fix a typo or whatever that the compiler balks at

Login to post a reply

Server time is: 2024-11-24 13:19:22
Your offset time is: 2024-11-24 13:19:22