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 / I wish there was a guide on how to write good Basic code.

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 10th Apr 2018 14:17
There is almost 2000 pages of documentation in the two guides, and then I have the glorious F1 on top of that! But while there's lots of information about the raw mechanics, there's no guidence on how to write good Basic code.

It would be super nice with a general guide on how to code in Basic. If I wanted to go Tier 2, I wouldn't have the same problem. There's truckloads of videos and books and classes on how to write OOP C++. But with Basic, I don't really know where I should find the info. Which is ironic, given that the language is aimed at teaching beginners. (Also, BASIC is too generic a word to google)

I also remember seeing a thread on what structure people used in their main.agc -- can't find it now, though. But there's good stuff in these threads:
Code Structure
Gosub is obsolete?
gosubs and goto are still ok?
State Machine Example [CODE - TIER 1]
Can AppGameKit Tier 1 do functional programming or OOP? What is the best way to code?
How do you manage your code?

Maybe the lack of a basic Basic guide has something to do with a lot of people here are extremely competent coders already. So while they need to look up which command does what, they already know exactly how good code goes. But for newbies, I think some general coding advice could be nice!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Apr 2018 16:18
I think that's a great idea. No doubt you will get 20 different (but equally useful) guides from 20 people though!!

Personally I try to keep everything in a relevant file. Sometimes this means I have lots of files but each one usually ends up pretty self sufficient and able to be moved into another project fairly modularly. This is because I tend to program in C# usually so I try to work in an object oriented way.

I am fairly messy and inconsistent though which is why I rely on resharper and visual studio (and when I am feeling like I need punishment I use style cop) to keep me in line. None of these tools are much use for AppGameKit Basic however...

It would be very interesting to see how others manage their code for sure.
Using AppGameKit V2 Tier 1
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Apr 2018 16:38 Edited at: 10th Apr 2018 16:50
I think the small game templates was intended to act as this sort of guide

https://forum.thegamecreators.com/thread/218621

Basic doesn't tend to have the same level of commonly accepted standards and best practices that you find with "industry" languages though.

For myself, I tend to take an "OOP by convention" approach, incorporating many of the principals of modularization, abstraction, namespacing, separation of duties, etc that you would find in such other languages even if these things aren't enforced or fully supported in Basic.
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: 10th Apr 2018 18:36
I agree with what Ortu said and I take the same approach using my OOP background in Java.

I don't think it matters what language you learn from, many of the same principles you see in those C++ books can be applied to any language. The only time I'd say where languages have a real distinctly different structure to coding is when you start comparing "normal" languages (basic, java, C, php, python, perl, etc) to stuff like Cobol or RPG. Possibly Fortran, but I honestly can't recall anything about the language. Whereas most languages allow you to indent and place code pretty much however you want (despite industry standards), Cobol is very strict on that space/tab being right there. Personally, I hated using cobol. Used to love pascal though.

What I'm trying to get at is you can learn good structure from pretty much any language and apply it to another.

I believe there is an AppGameKit book, does it not cover topics on code structure? If not, I'd love to make something but I simply wouldn't have the time.
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
Alistair
18
Years of Service
User Offline
Joined: 4th Oct 2006
Location: Scotland
Posted: 11th Apr 2018 07:32
The AppGameKit books, although without a specific chapter on program structure, defines, after covering the basics, a single fixed structure for all the programs in the two volumes so I would certainly hope anyone who has taken the trouble to work through them fully will have developed an organised approach to their programming.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 11th Apr 2018 09:29
One of the things I miss most from my C64 days is typing in all those programs from magazines. You learned a lot from doing that. Many of the magazines have been uploaded to the web archive site, some of the magazines have code that can be ported to AppGameKit fairly easily. https://archive.org/details/computermagazines&tab=about. A couple of my favorites were Compute! and Creative Computing.

Another couple of favorites of mine were the books Basic Computer Games and More Basic Computer Games. However, these books use a much older version of basic with lines numbers, 2 character variable names, and no functions, using a bunch of GOTOs and GOSUBs instead. Still would be fun to port some of these to AGK.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 11th Apr 2018 11:03 Edited at: 11th Apr 2018 11:05
Its definately worth taking a look at alistairs older book which covers the very basics of programming in AppGameKit with at least some structure
www.digital-skills.co.uk/samples/agk218e.pdf

There are plenty of good books on ebay on writing in basic and still some tutorials floating around the web. Even old books on visual basic are valid in terms of code structure but learning it for yourself can be very useful.

The Example games are worth getting as they are a good way to look at how others have written games. A few of those I dont actually like the way they were written and wouldn't write code that way myself though.

A lot of it is personal preference and just good organisational skills.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Apr 2018 12:47
Quote: "One of the things I miss most from my C64 days is typing in all those programs from magazines."


I think the internet killed that. I miss getting the free amiga game disks with magazines.
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
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 11th Apr 2018 13:23
@tomroad: "However, these books use a much older version of basic with lines numbers, 2 character variable names, and no functions, using a bunch of GOTOs and GOSUBs instead."

Well, the Goto or Gosub stuff may have lost its relevance for 'proper' coding, however it is still useful if you want a function to skip certain parts of a function's code based upon a certain condition. I actually do sometimes use Goto / Gosub stuff.

Anyway, just wanted to say Alistair's Guides (vol 1 and 2) are well worth getting in terms of learning about good code structuring too. It should give a good idea how to efficiently initialize objects and level contents etc, but also keep functions organized well enough not to lose track of what's going on. Honestly, I still think some of the examples given should perhaps be part of the official F1 help.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 11th Apr 2018 14:13
I think new coders should concentrate at first on understanding program flow, variable usage and such and not worry so much on structure as this will come with experience and each will develop his own style, its true the first 20 or so projects will go in the bin anyway as they learn more, once they get to grips with the whole concept they will find there own style, trying to adopt another programmers coding style while not understanding what that programmer is actually doing will ultimately lead to bad code.

but that being said the one thing I would recommend to anyone coding in any language is "know and understand finite state machines (FSM)" as these are vital IMO to a well-structured code framework and use constants for your state declarations, event loops can become very messy and impossible to maintain very quickly, using a FSM will take most of the pain out of the process and using constants makes it clear what each state is actually doing.

Also, this is a personal preference, but I like to write event-driven code, my FSM will call event functions which in turn call the logic code so the only code in the event loop is the FSM, no logic, no mess, just a state switch and a bunch of single function calls to event functions for each state, this segregation really helps to isolate issues and adding states is easy.

But above all I think the single most important bit of advice to give a new or old coders alike, is comment, comment and comment again, its clear to you what the code is doing while you are writing it but return to that code a week, month, year later and you soon get lost in trying to remember or understand your train of thought at the time of writing, I give this advice but I am not so good at taking it and I wish commenting code was a habbit I got into years ago but its only as I revisit old projects I feel the pain of my lack of comments

I have been a hobbyist programmer for over 15 years and I would like to think I am fairly capable but I still find ways to improve as I write more and more, I don't think any definitive guide on how to structure code could apply to all programmers but a definitive guide on what NOT to do could really help out new coders.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 11th Apr 2018 17:51
Quote: "I think the internet killed that. I miss getting the free amiga game disks with magazines."


Has it though?

There is so much freely accessible source code available on github, stack overflow, blogs, tutorials, and forums like these.

Just because you can copy paste or download in full doesn't mean you have to or should.

Anytime I am trying to learn something new from such sources I type it out by hand whenever i can, even change the naming and structure around, because you really do learn more deeply when you actually have to work with it line by line.
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.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th Apr 2018 01:40 Edited at: 13th Apr 2018 01:41
Quote: "Goto and gosub is not obsolete its just bad programming practice and much better to use function calls"

The language commands section in the helpfile makes a list of available commands and how to use them including goto and gosub
https://www.appgamekit.com/documentation/language.html

I also agree the templates were written as a guide to help new users
and the following video tutorials
AGK First Video Tutorial - Random number guessing game
https://forum.thegamecreators.com/thread/188244

AGK video tutorial one hello world sprites and more
https://www.youtube.com/watch?v=CbC7ju2kew8&list=PL62008E8509FB652B&feature=plcp

AGK Video tutorial two physics sounds sprites
https://www.youtube.com/watch?v=NR9sutVdBmg&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial three scrolling sprites
https://www.youtube.com/watch?v=rQ1-Zw6SGbk&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial four cameras and more
https://www.youtube.com/watch?v=kWAfHgrBb-M&feature=BFa&list=PL62008E8509FB652B

AGK Video tutorial five putiing your app in xCode
https://www.youtube.com/watch?v=EF5liNrFxMY&feature=BFa&list=PL62008E8509FB652B

I hope that helps
fubar
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 13th Apr 2018 05:38 Edited at: 13th Apr 2018 05:41

A guy called TDK_Man wrote various principal tutorials in the DarkBASIC space, while not cut','paste friendly the concepts are the same..

A quick search found [STICKY] TDK's Programming Tutorials For Beginners [DBC/P]



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code

Login to post a reply

Server time is: 2024-11-23 21:35:07
Your offset time is: 2024-11-23 21:35:07