Critics and Advises to BlitzMax Tutorial

Started by Midimaster, December 22, 2021, 18:29:18

Previous topic - Next topic

Hotshot

if you using NON Functions then Used LOCAL Commands but if you using FUNCTIONS then Global commands is must otherwise you will get ERROR!




therevills

I know that BMX is a case insensitive language, but I like to use a nice clear consistent coding standards.

For example for local variables I use camelCase:
Local myLocalVariableX:Int = 3

For globals I use PascalCase:
Global MyGlobalVariableY:Int = 10

And for constants I use all UPPERCASE, separated with underscores:
Const GRAVITY_VALUE:Float = 9.81






zelda64bit

I'm really liking your tutorials, please don't leave it. :)

Baggey

I can only say thankyou so much for your intuitive Tutorials.  8)

Please keep up the good work.

I soon think i maybe able to put a game together myself. Ive always learnt by example and adapted code that suits my need. Picking up a book and going from there just dosent work for me.

I tinker with code re-write it alter things and when i get a result i want. Ive learnt something.

So thankyou for all your teaching's and may there be many, many more!

Merry Christmas and a Happy New Year!

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

#19
Been following this today.  ;)

Ive got this far. Does my chicken have to be 60x40? I suppose i could try one and see thou!?

Happy Coding

My Chicken has hatched ive replaced her! Looking forward to see how she blends in or mask's into the background? I suppose you have your own chicken anyway.  :)

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

zelda64bit

I keep this chicken, because Midimaster has not put any for download. ;D

Midimaster

...back from Egypt

zelda64bit

Quote from: Midimaster on December 30, 2021, 17:32:14
tonight it will come! but animated!!!!

Much better this chicken, how far do you plan to go with the tutorials?.

Baggey

Just Finished Lesson IX and am learnig lots of neat little tricks! Love your Chicken. Thankyou so much.  :D


I Cant help noticing the compile window throwing up errors to Argument #1 and Argument #2 etc..
Building Hyper_Chicken
[ 98%] Processing:Hyper_Chicken.bmx
Compile Warning: In call to Function DrawImage:Int(image:TImage,x:Float,y:Float,frame:Int). Argument #2 is "Double" but declaration is "Float".
[C:/Chicken/Hyper_Chicken.bmx;31;0]

Compile Warning: In call to Function DrawImage:Int(image:TImage,x:Float,y:Float,frame:Int). Argument #3 is "Double" but declaration is "Float".
[C:/Chicken/Hyper_Chicken.bmx;31;0]

Compile Warning: In call to Function DrawNonFilledRect(X:Int,Y:Int,W:Int,H:Int). Argument #1 is "Double" but declaration is "Int".
[C:/Chicken/Hyper_Chicken.bmx;67;0]

Compile Warning: In call to Function DrawNonFilledRect(X:Int,Y:Int,W:Int,H:Int). Argument #2 is "Double" but declaration is "Int".
[C:/Chicken/Hyper_Chicken.bmx;67;0]

[ 99%] Compiling:Hyper_Chicken.bmx.gui.release.win32.x64.c
[100%] Linking:Hyper_Chicken.exe
Executing:Hyper_Chicken.exe



I can clearly see the game is working is this because the variables being passed are smaller then required.

I assume a variable being passed that is bigger than required would throw errors.

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

#24
this are no "Compile Errors", but "Compile Warnings". You often can ignore them. This mean the compiler can handle our given code, but informs you that the author of the function expected a different variable type.

We defined the chicken's movement variables as (new style) DOUBLE floating point, because we want to move them smooth. The drawing functions expects (old blitzmax) FLOAT floating point. In former times this type was faster to process. I think Brucey already started changing them all towards DOUBLE.   

For drawing it is not necessary to have a better precision. And BlitzMax can change the type of variable when handover them. We call this "Casting".

My new drawing function DrawNonFilledRect() only needs INTEGERs to work exact enough. So it expects INTEGER. But you can handover any type, because BlitzMax automatically casts them to INTEGER.

If you want you can "optimize" the DrawNonFilledRect()-Function by expecting DOUBLEs:
Function DrawNonFilledRect(X:Double, Y:Double, W:Double, H:Double)
This prevents the "Compile Warning", but impacts the perfomance negatively.

So handing over variables is always a compromis and casting is expected as "normal".
...back from Egypt

Scaremonger

In post https://www.syntaxbomb.com/tutorials/learning-basic-for-total-beginners-blitzmax-ng/msg347054206/#msg347054206

Quote
But now we also can call all 10 together with a For/Next-loop:
Code: BlitzMax
For local i:Int=1 to 10
     If carX<0 then carX=0
Next
....
For local i:Int=1 to 10
     DrawImage carImage, carX, carY
Next

You should be using "0 until 9" in those loops (or "0 until 10").

Si...

Midimaster

You are right..but...
I thought a lot of time about this, but in "real life" the things with indices start by 1, never by 0: "This is my first car" "and the second was a Cadillac".

We should always search for parallels in the (well known) real world to explain new stuff.

So for a beginner it is difficult to understand why the first thing should be called with Thing[0]. This makes the understanding of arrays unnecessarily difficult.

It is difficult for us to go back to the time when we were still ignorant after all these years of experience. Only in the contact with newbies you can see the problems they have. And think about the fact, that not all languages start with a zero-index.

So using the values "1" to "10" instead of "0" to "9" for 10 things and defining the array to big (100) is a compromiss and produces no runtime error.

...back from Egypt

Derron


Global carX:Int[100], carY:Int[100]
carX[1]=253
carX[2]=524
...


but this will lead to an error somewhen ... if one tries to do "carsX[100] = 1234"

always start with 0 here - and emphasize, that as in most languages also blitzmax is "zero" based. Some languages are 1 based (or sometimes even just some python libraries ...)


bye
Ron

Midimaster

Quote from: Derron on January 19, 2022, 08:29:39
...
but this will lead to an error somewhen ... if one tries to do "carsX[100] = 1234"

Ron

Yes and No!

No,because... In the example we talk about 10 cars. So the student will perhaps use carX[10] as his last car. This would work.

Yes,... This would cause a runtime-error, but also when the student starts with carX[0] and carX[100] uses . And also if we dimension the array to Global carX:Double[10]. That challenges him to investigate more about limitations of arrays.

My explanation in this lesson is enough sufficient for a first touch with arrays.

...back from Egypt

Derron

I disagree.

It just leads to the student learning wrong things ... and is left alone with assumptions.
local i:int[10]
i[1] = ...
i[2] = ...
It just leads people memorize incorrect assumptions.


Better just use the chance to add 2 sentences about arrays and "indexes". An "index" in BlitzMax starts at "0". So the first element in an array has the index 0, the last element has "array.length minus 1". If it is easier to understand, then think of an "index" as "offset". Offsets also start at 0,

Btw TList.ValueAtIndex() also starts at 0, the top left pixel is also written at "0,0" and not at "1,1"


bye
Ron