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 / My top ten tips on programming design

Author
Message
damothegreat
User Banned
Posted: 14th Oct 2016 20:33 Edited at: 29th Jan 2017 20:17
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Oct 2016 12:09
Could be a useful thread

Quote: "2. Try and declare all your variables that you use throughout your project also at the beginning of the main.agc before any nitty gritty coding is made
eg,

Global
Dim
Arrays [ ]
Types"


Dim is a legacy declaration, you shouldn't use this anymore.

Quote: "4. Try to avoid "load" and "create's" functions within main game loops
eg,
CreateSprite..........
LoadSound........"


I agree with trying to avoid loading of assets. However creating sprites, sound instances etc should not be an issue. This is simply wrapping existing assets into a small packet of data.

Quote: "5. Try to avoid Loops within loops within loops - eg using of re-cursive FOR loops."

This is a good tip to be wary of, but not something that has to be avoided. You need to be aware of the implications. That is, an outer loop of 5 iterations with an inner loop of 5 iterations is 25 executions of the inner code.
But there are scenarios that require this. If I have 6 characters with 6 attributes then I need a nested loop to process all 36 attributes.
Technically this isn't recursion. Recursion is where a function calls itself.


I look forward to more tips that can be discussed and fine-tuned to help newcomers. It would be good to maintain the definitive list in your first post.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Oct 2016 15:20
Avoid defining/embedding data directly in the code, load it from external sources/resources. Hard coded data is inflexible, harder to edit, and forces more recompiling.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 15th Oct 2016 17:54
I disagree with points 2 and 3 from the OP's post.

2) When working with multiple source files, I find it much easier and clearer to keep variable declarations at the top of the relevant source file.

and

3) Although I agree that Goto is evil, Gosub on the other hand is a respectable command with genuine advantages over functions for certain applications.

I'd like to add also that sensible variable names and comments are essential for larger/longer term projects. That, and save often, and back up your saves
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Oct 2016 22:00
Quote: "Dim is a legacy declaration, you shouldn't use this anymore."

It is? What's the alternative for declaring arrays in agk then?

Quote: "When working with multiple source files, I find it much easier and clearer to keep variable declarations at the top of the relevant source file."

Agreed. Afterall the whole reason I use multiple files to keep a modular design. No sense in declaring vars in one file if you only see them in code in another file.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Oct 2016 11:18
Quote: "What's the alternative for declaring arrays in agk then?"


global myArray as string[3]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 24th Oct 2016 14:40
Quote: "
3) Although I agree that Goto is evil, Gosub on the other hand is a respectable command with genuine advantages over functions for certain applications."


Can you please give an example where Gosub has genuine advantages over functions?
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Oct 2016 17:14
I believe that gosubs just jump to another place on the heap, whereas a function needs to add itself to the stack each time you call it.
Having said that, I always use functions and never use gosubs. I like my code to be readable, self-contained and portable between projects.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Oct 2016 17:18
Only case I can think of is to access many non global, top level scope variables (ie: too many to pass and return from a function). Not a common thing.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 24th Oct 2016 18:48
Ortu wrote: "
Link
Only case I can think of is to access many non global, top level scope variables (ie: too many to pass and return from a function). Not a common thing. "


If your function expects more than 3 parameters, something is probably wrong with the function. It's probably doing to much.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2016 23:47
I use gosubs a lot. It helps me organize large chunks of code that don't need to be functions.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
User Banned
Posted: 28th Oct 2016 13:27 Edited at: 29th Jan 2017 20:17
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 28th Oct 2016 22:16
@damothegreat
Not programming advice, but forum advice really...



@Carharttguy
All my included files are made up like this



Then, when I include the file, I simply add these couple of lines near the top of the main.agc file



This allows me to keep all the variables in the scope of the main loop (Avoiding nasty nasty globals), and keep all the declarations and functions associated to a single agc file.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 29th Oct 2016 02:00
@Prof

My include modules are structured and handled almost exactly the same way


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Oct 2016 22:57
This:



is functionally the same as this:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 30th Oct 2016 01:42
Interesting, dbp doesn't have #insert. Does it just inject any code outside of a function into the point of the insert?

Do you need handling for the case of multiple modules each calling the same insert module?

What if you wanted to reinitialize a module later, wouldn't you still need to wrap the initialization into a callable routine?


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Oct 2016 08:42
It is the equivalent of copy and paste. It just drops whatever is in the file into that position in the code. You could do something bizarre like this and it would work...




where codesnippet.txt is just a line of code...



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 6th Nov 2016 12:40
@BatVink:
Nice, You learn something new every day.

Login to post a reply

Server time is: 2024-03-29 10:51:50
Your offset time is: 2024-03-29 10:51:50