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.

AppGameKit Classic Chat / Is type better than global?

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 20th May 2018 14:14


or:



Of course, if I want to create 200+ individual turtles, it makes sense to make an array of turtle types. But is there anything won by creating a single game type?
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 20th May 2018 16:34 Edited at: 20th May 2018 16:35
On the above your type is still being made a global :p

The question then is type better than individual variables?

The answer of course is "it depends"

Types are organizational structures. If they help you organize, then they are better. If they create unneccessary complication, then maybe not. It really depends on the data used in any given situation
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th May 2018 22:29
Will you ever need to pass all this data together into a function? If yes, then a type is the way to go as it'll be easier passing 1 variable rather keeping track of multiple parameters.

And this is me just nitpicking, but in your first example you write GAME in all caps. Generally speaking, constants are all capitalized. But it's up to you as it really makes no difference on the code other than general readability.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 21st May 2018 11:51
Thanks guys! I traced down the source which made me think about this: Page 546 in the AppGameKit official tutorial guide:



The argument for a global game type is that it is a smart way to make everything within it global.

And I can see that it is somehow more neat to have it all inside an overall type. Kind of like how I don't like placing file directly in the root of my external drives, but always creates folders. I guess this is mostly down to personal preferences.

Yet, it look like types can easily be saved/loaded to the harddrive using JSON:

https://www.appgamekit.com/documentation/guides/12_array_changes.htm

So ease of saving/loading could be a reason to put stuff into types, maybe.

Regarding UPPERCASE, I think it's great that BASIC is ignoring case. Other languages should copy this! Yet, I'm still unsure what use of case gives the best readability. BTW, Vintage BASIC code prefers to type everything except variables in uppercase.

Login to post a reply

Server time is: 2024-11-18 12:43:52
Your offset time is: 2024-11-18 12:43:52