Helpful Hints for Newbie BlitzMax Users

BlitzMax Forums/BlitzMax Beginners Area/Helpful Hints for Newbie BlitzMax Users

Macguffin(Posted 2008) [#1]
Hey all,

(Last Edited August 21. 2008)

I started using BlitzMax in March, and came across a couple showstopping issues on my end that I had to figure out. Since I know how easy it can be for someone to get discouraged up front, I wanted to post some easy-to-find answers for the issues I ran into. Over time, this post got stickied, and I've kept adding things that I thought could be helpful. Please feel free to post in this thread with things you think should get added. Thanks!

- You can find all the tags for posting to these boards here.

- The Beginner's Guide to BlitzMax is a great place to start, but there are some issues with the examples. This can be a good thing, in that you'll have to think harder to make it work. :)

- In the IDE, hitting F1 once while the cursor is on a native function will bring up the function parameters at the bottom of the window. Hitting F1 twice will bring up the manual page for that item. This can be really handy to get a better idea of the keyword you're using from a tutorial.

- You can run in Strict or SuperStrict mode when you code in BlitzMax. Strict forces you to delclare all variables before using them; SuperStrict forces you to declare all variables before using them AND to identify what type they are (string, int, etc.) It's recommended you work in SuperStrict, since it will both cut down on your errors, and force you into slightly better coding habits. If you want help from people in the forums and show your code, this will be the first thing you get told to do.

- When declaring variables, you need to put the scope before it (Local or Global) and the type immediately after it. So where in non-Strict you might have put:

X = 10
In Strict, in order to delcare X locally and assign it on the fly you will need:

Local X = 10
And in SuperStrict you will need to additionally make sure to type the variable:

Local X:Int = 10
The one way to type your variable is to put a colon after it, then the type identifier (Int, String, etc.). The other is to use a shorthand identifier like so:

Local X$ = "Foo"   'defines X locally as a string variable and assigns "Foo"
Local X% = 10  'defines X locally as an int variable and assigns 10 to it.
You are most likely better off using the longer identifiers, since it improves the readability of your code.

- Some of the explanations in the tutorial are going to be confusing if you don't understand the basics of pass-by-reference and pass-by-value (I'm specifically referring to Page 9 where it gets to Types)

- Assari has a fantastic set of links and documentation here. This includes a much more search-able version of the helpfiles.

- SebHoll has created a great tutorial on how to use TortoiseSVN to sync to the development version of BlitzMax. SVN (aka Subversion) is a file version control system, and TortoiseSVN is a version that integrates Subversion into Windows Explorer and right-click menus on Windows. PLEASE NOTE: the dev version is not the release version. If you don't have a reason why you'd want to be working on the newest (possibly unstable) version, just use the current release.

- Lua support is available for BlitzMax. Check out this thread here. Note - you need to grab the zip he lists at the bottom. Module syncing has been removed for 1.30. (Further Note: This module was last updated for 1.26 or so. Use at own risk.)

- Please do a forum search or two to answer questions you have before posting. People on here are amazingly helpful, and will often answer questions by writing new code to show you how something works. If you show up with a lot of basic questions early, you might wear out the good will. Also - the forums are an amazing resource, chock full of answers and code samples on a huge array of questions. (No pun intended.)

- The built-in blitzmax.com search functionality is a bit dated, but you can do a google search on the site instead. Simply start your google query with "site:blitzmax.com", then enter your search terms.

- Another tip is to use the debugger! (Program Menu/Build Options/Debug Build). You can compile your code in normal (release) mode or debug mode (which takes longer to compile). When in debug mode everything runs slower but if your code crashes, the line it crashed on will be highlighted and you can examine all the variables in the panel on the right-hand side. Also you can force you code execution to stop by using DebugStop in your code. This is useful for checking out certain variable values at specific times of your choosing. Once the code has stopped due to DebugStop you can then step through it one line at a time (and skip over functions if need be). The Debugger is pretty useful for getting to the bottom of why an algorithm doesn't work, or even just to test that it DOES work as expected! (Thanks to Grey Alien for this tip.)

- It's probably worth investing the other more advanced IDEs which are available such as BLIDE or Project Studio IDE (there are more). (Thanks to Grey Alien for this tip.)

- Embrace OOP. Don't code in old-style "arrays" and "structs" and functions. Create types (classes) and use methods and inheritance and polymorphism. It's much more flexible and makes for great code re-use + it's good fun. There's loads of tutorials about BMax OOP around. (Thanks to Grey Alien for this tip.)

- degac has created the BlitzMax Companion, which will install a number of useful utilities to your system for use with Blitz - this includes minGW & its environment variables. You can find info here. Although I haven't used it myself, it is getting great reviews and looks extremely handy.


- One of the great things about BlitzMax is that it is easy to bolt on modules and other middleware. Some notable ones are:
- Brucey's Modules - Brucey is the prolific creator of a number of really great modules for all sorts of purposes. You most likely don't need to worry about most of them until later on, since they tend to fill specific (and usually more advanced) needs. Find out more about them here.
- Grey Alien's Framework - The framework is a pair of include-able code files that supply an overall structure to your game, a fixed iteration timing loop (important to keep gameplay smooth), and a number of Types to support UI functionality, images - lots of stuff. GA's website is here.
- The code archives here on the Blitz site has an amazing range of work - from code snippets on up to full programs - that cover a huge number of topics. There's a decent chance that, whatever issue you're running into has been solved by someone and posted there as public domain code.


Gabriel(Posted 2008) [#2]
Good idea. This should probably be sticky'ed, particularly since the demo hasn't been updated in so long.


GfK(Posted 2008) [#3]
Its a bit confusing since, in Add/Remove Programs, it says "BlitzMax 1.18", even though I have the 1.28 update installed.

They should probably fix that. You don't really want version numbers in there, especially when they're wrong.


Macguffin(Posted 2008) [#4]
Updating as I work my way through the Beginner's Guide. Also, I'm starting to post questions to the community in the body of the post where applicable. I'm happy to update if people have answers.


Perturbatio(Posted 2008) [#5]
I would suggest always using superstrict and always use the name of the variable's type (i.e. int, float, double and string) instead of it's shorthand version (%, #, ! and $).

They still confuse me somewhat.


Czar Flavius(Posted 2008) [#6]
Bad '


pmc(Posted 2008) [#7]

I would suggest always using superstrict and always use the name of the variable's type (i.e. int, float, double and string) instead of it's shorthand version (%, #, ! and $).

They still confuse me somewhat.



I'm using Blide and it recently started to automatically change my shorthand to the longer version -- maybe I changed a preference. That's fine with me since I can never remember which symbol is what (except for $tring of course). The only problem is that sometimes longer lines of code can get very verbose.

-pmc


Perturbatio(Posted 2008) [#8]
longer lines of code can get very verbose.


I prefer verbose over confusing.


Macguffin(Posted 2008) [#9]
Updated to recommend the longer variable type designations, and added a link to Assari's links & resources page.


Macguffin(Posted 2008) [#10]
Updated to add SebHoll's Flash tutorial on using SVN with Blitz.


Macguffin(Posted 2008) [#11]
Woo! Stickied. I won't put new messages here when I update, I'll just update the date at the top of the post.


Grey Alien(Posted 2008) [#12]
Good idea for a thread. Another tip is to use the debugger! (Program Menu/Build Options/Debug Build).

You can compile your code in normal (release) mode or debug mode (which takes longer to compile). When in debug mode everything runs slower but if your code crashes, the line it crashed on will be highlighted and you can examine all the variables in the panel on the right-hand side. Also you can force you code execution to stop by using DebugStop in your code. This is useful for checking out certain variable values at specific times of your choosing. Once the code has stopped due to DebugStop you can then step through it one line at a time (and skip over functions if need be).

The Debugger is pretty useful for getting to the bottom of why an algorithm doesn't work, or even just to test that it DOES work as expected!

Another tip. It's probably worth investing the other more advanced IDEs which are available such as BLIDE or Project Studio IDE (there are more).

Another tip: Embrace OOP. Don't code in old-style "arrays" and "structs" and functions. Create types (classes) and use methods and inheritance and polymorphism. It's much more flexible and makes for great code re-use + it's good fun. There's loads of tutorials about BMax OOP around.

Final tip: ahem, get my framework, you won't regret it ;-)


Macguffin(Posted 2008) [#13]
Thanks, GA. I've put up your suggestions, as well as a plug for the Framework. Please speak up if you have middleware solutions that you'd like mentioned.


Grey Alien(Posted 2008) [#14]
Thanks!


bazziman(Posted 2008) [#15]
"Another tip: Embrace OOP. Don't code in old-style "arrays" and "structs" and functions. Create types (classes) and use methods and inheritance and polymorphism. It's much more flexible and makes for great code re-use + it's good fun. There's loads of tutorials about BMax OOP around."

Amen brother. After my AMOS days (10 years ago?), and a short flirtation with BlitzPlus and C+ I've just discovered this great feature of Blitz (thanks to the beginners guide, which whilst not perfect surely beats the documentation provided with Blitz) and the 'type' OOP is superb...once you figure it out it saves you soooo much headaches.


Macguffin(Posted 2008) [#16]
Removed references to 1.28, since the current version is now 1.30.


Macguffin(Posted 2008) [#17]
Added info on degac's BlitzMax Companion.

Changed my mind - I'll keep putting update notes in. It shows the thread has been edited recently. ;)


alevy(Posted 2010) [#18]
Thanks i just downloaded this program and thanks for the heads up:)


Predsel(Posted 2016) [#19]
Hi. New BMX user here. Came for an answer to what the "#" symbol meant. And I now see the answer is in a post above. It's simply shorthand for declaring a FLOAT variable.

Sure wish I could have found that by searching the forums! lol


RustyKristi(Posted 2016) [#20]
Yes or you can just use MyFloatVariable:Float (for Strict coding I think) since now you're using Blitzmax :)


Predsel(Posted 2016) [#21]
Thank you, RK! And thank you Perturbio for your post. Simple, but essential for newbs examining samples.


Bobysait(Posted 2016) [#22]

or you can just use MyFloatVariable:Float (for Strict coding I think)



You can still use "#" and/or ":Float" syntax in Strict (and SuperStrict) modes.

All thoose type specifiers (
- "@"->Byte
- "@@"->Short
- "%" -> Int
- "%%" -> Long
- "#" -> Float
- "!" -> Double )
Are really just shortcuts for the full litteral ones (or kind of preprocessor symbols that are replaced with the expression at compile time).

What Strict affects is the explicit "Local/Global/Const" declarations
SuperStrict makes explicit typedef mandatory, so that you have to declare all "Int" or "%" type for variables. (else, whithout superstrict, you could define a variable without type which mean the variable is an Int by default)
It also affects the scope for Local variables, ex

no strict mode : you can use the "Local" keyword, but it's not mandatory ... but it's also a way to generate errors
   MyLongNameVariable = 12
   MyLangNameVariable = MyLangNameVariable+1

the variable is mispelled, but you failed to see it and the compiler don't care because it doesn't require to declare the "Local/Global"

In strict and superstrict mode :
   Local MyLongNameVariable = 12
   MyLangNameVariable = MyLangNameVariable+1

This fails to compile because MyLangNameVariable is not declared, so you directly find the mistake.


There is also a behavior related to loop declaration
In strict mode
Function do()
   Local i
   For i = 0 to 5
   Next
   For i = 0 to 5
   Next
End Function
Function do2()
   For Local i = 0 to 5
   Next
   For Local i = 0 to 5
   Next
End Function

This generates an error because i is declared two times in the function "do2" -> strict mode doesn't care about internal scopes (For/Next, While/Wend etc ...) so if you use two times a Local keyword for the same variable on the same function, it is duplicate declaration.


In SuperStrict mode : the local can be defined in the function body, or for each loop (For/Next)
Because
Function do()
   Local i
   For i = 0 to 5
   Next
   For i = 0 to 5
   Next
End Function
Function do2()
   ' this i variable is a function variable
   Local i = 2
   ' this i is relative to the loop
   For Local i = 0 to 5
       ' here i will go from 0 to 5
       ' it's actually another variable even if it is named the same
   Next
   ' at this point i is still 2
   
   ' same for this i, it is relative to the for loop
   For Local i = 0 to 5
   Next
   
   ' and here i is still 2.
End Function


So, it's sometimes hard to notice that we used a variable in a loop that is local and does not affect the function body.