Community Project: BlitzMax Examples in Helpfiles

BlitzMax Forums/BlitzMax Programming/Community Project: BlitzMax Examples in Helpfiles

***Update July 9th,
New milestone reached.More than 60% of functions/methods now have examples.
The latest version can be downloaded from http://www.2dgamecreators.com/files/
--------------------------------
Hi,
I have created a system whereby user examples can be appended to the official document which is then produced as a compiled helpfile.

The plan is for users to contribute examples in this thread and I will transfer them into the compiled helpfile. There is a table showing which functions already have example(s) so we can concentrate on those without. See http://www.2dgamecreators.com/files/examples.htm

Current score: 30% of ~750 total functions have examples

To Contribute code to this thread, the contributor has the rights to the code and declares said code as public domain.

Depending upon number of contributions, I will endeavour to update the table and helpfile at least once a month until we reach a level of 90%.

Code Entry: AppSuspended
SuperStrict

SetGraphicsDriver GLMax2DDriver()
Graphics 800,600

While Not KeyHit(KEY_ESCAPE)
	Cls
	If AppSuspended() = True
		DrawText "Application Suspended!",10,10
	Else
		DrawText "Application Running...",10,10
	EndIf
	Flip
Wend


Under what copyright/licencing are you releasing the help-file?

Note, that you may need to fully cover the various situations that can happen for a specific function/command, like: 2d, GUI, non-hooked and hooked, with globals, without globals, etc. In addition, examples should be as small as possible, not like having a zillion lines of code with a zillion different -difficult- things to find your way through.
Because of all this, I recommend that someone looks into the given examples to make 'em "complete" and uniform.

If you start dissecting it like that, it will become hell on earth for beginners to understand anything.

Nah, check B+ manual: Appendix 2 'five ways to say Hello World'. That's exactly what's needed: multiple examples of the same thing, in all kinda forms and shapes. Non-GUI, GUI etc. One example might not be able to teach something, but multiple examples doing the same thing will!

North: Thanks

Otus: As far as I am concerned the original docs belong to BRL, all I'm doing is compiling them. The reason for asking the code to be public domain is to allow BRL, if they so wish, to incorporate the examples into the docs directly.

CS_TBL:The contributions can cover any/all variation of the functions. The system can cope with multiple examples for the one function. I will try to do some editing but no guarantees on 'complete' & uniform :)

so, examples should be emailed to you, or posted here?

+ should always superstrict be assumed? (matters in declaring variables)

CS_TBL:posted here. Superstrict would be better

Then there's the situation of commands belonging together, like the whole bank family. You want want -in case of the banks- a big example having all the pokes and peeks 'n stuff, or unique examples tailormade for each poke/peek flavor?

The objective is to have clear examples. Most of the time unique is better but sometimes multiple flavors in a single example can clarify concepts.

This is a very nice community project and I'd like to contribute. Since this just started, may I suggest to setup a small and easy wiki to collect all entries?

Using a forum topic will end in a mess. It will become a pain to check what's already covered, what have changed, bugfixed etc...

Are there any free hosted Wikis around we could use? Like free forums...no complicated setup, just register and go.

Not all bank thingies, but at least most of 'em.

Rem
'
' CreateBank
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End



'
' PokeByte
'
' Pokebyte puts an unsigned byte value into a bank, at a given address
'


Local MyBank:TBank=CreateBank(16)

PokeByte MyBank,0,123
PokeByte MyBank,15,234

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End


'
' PokeShort
'
' PokeShort puts an unsigned short value (2 bytes) into a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. A short value should not be poked at the last possible byte address of the bank.
'


Local MyBank:TBank=CreateBank(16)

PokeShort MyBank,0,256
PokeShort MyBank,14,32768+1

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End



'
' PokeInt
'
' PokeInt puts a signed int value (4 bytes) into a bank, at a given address. Take notice not to exceed the boundaries of
' the bank. An int value should not be poked at the last possible byte or short address of the bank.
'


Local MyBank:TBank=CreateBank(16)

PokeInt MyBank,0,-10000001
PokeInt MyBank,12,31415926

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End


'
' PokeLong
'
' PokeLong puts a signed long value (8 bytes) into a bank, at a given address. Take notice not to exceed the boundaries of
' the bank. A long value should not be poked at the last possible byte, short or int address of the bank.
'


Local MyBank:TBank=CreateBank(16)

PokeLong MyBank,0,-10000001234567
PokeLong MyBank,8,31415926000000

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End


'
' PokeFloat
'
' PokeFloat puts a signed float value (4 bytes) into a bank, at a given address. Take notice not to exceed the boundaries of
' the bank. A float value should not be poked at the last possible byte or short address of the bank.
'

Local MyBank:TBank=CreateBank(16)

PokeFloat MyBank,0,0.123456
PokeFloat MyBank,12,1234.5678

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End



'
' PokeDouble
'
' PokeDouble puts a signed double value (8 bytes) into a bank, at a given address. Take notice not to exceed the boundaries
' of the bank. A double value should not be poked at the last possible byte, short, int or float address of the bank.
'

Local MyBank:TBank=CreateBank(16)

PokeDouble MyBank,0,123495543.12342345123
PokeDouble MyBank,8,121235567.89015678123

For Local t:Int=0 To BankSize(MyBank)-1
	Print PeekByte(MyBank,t)
Next

End


'
' PeekByte
'
' PeekByte reads an unsigned byte value from a bank, at a given address.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
Next

Print PeekByte(MyBank,0)
Print PeekByte(MyBank,1)

End


'
' PeekShort
'
' PeekShort reads an unsigned short value (2 bytes) from a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. A short value should not be read from the last possible byte address of the bank.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

Print
Print PeekShort(MyBank,0)
Print PeekShort(MyBank,1)
Print PeekShort(MyBank,14)

End


'
' PeekInt
'
' PeekInt reads a signed int value (4 bytes) from a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. An int value should not be read from the last possible byte or short address of the bank.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

Print
Print PeekInt(MyBank,0)
Print PeekInt(MyBank,1)
Print PeekInt(MyBank,12)

End


'
' PeekLong
'
' PeekLong reads a signed long value (8 bytes) from a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. A long value should not be read from the last possible byte, short or int address of the bank.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

Print
Print PeekLong(MyBank,0)
Print PeekLong(MyBank,1)
Print PeekLong(MyBank,8)

End


'
' PeekFloat
'
' PeekFloat reads a signed float value (4 bytes) from a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. A float value should not be read from the last possible byte or short address of the bank.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

Print
Print PeekFloat(MyBank,0)
Print PeekFloat(MyBank,1)
Print PeekFloat(MyBank,12)

End


'
' PeekDouble
'
' PeekDouble reads a signed double value (8 bytes) from a bank, at a given address. Take notice not to exceed the
' boundaries of the bank. A double value should not be read from the last possible byte, short, int or long address of
' the bank.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

Print
Print PeekDouble(MyBank,0)
Print PeekDouble(MyBank,1)
Print PeekDouble(MyBank,8)

End


'
' SaveBank
'
' SaveBank saves the content of a bank to a file.
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

SaveBank MyBank,"c:\mybank.dat"

End


'
' LoadBank
'
' Loads a file into a new bank, created by the LoadBank function
'

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To BankSize(MyBank)-1
	PokeByte Mybank,t,Rnd(255)
	Print PeekByte(MyBank,t)
Next

SaveBank MyBank,"c:\mybank.dat"


Local MyNextBank:TBank=LoadBank("c:\mybank.dat")

For t=0 To BankSize(MyNextBank)-1
	Print PeekByte(MyNextBank,t)
Next

End




' How to properly write several int values into a bank:

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To 3
	PokeInt MyBank,t*4,Rnd($12345678)
Next
End


' How *NOT* to properly write several int values into a bank:

Local MyBank:TBank=CreateBank(16)

For Local t:Int=0 To 3
	PokeInt MyBank,t,Rnd($12345678)
Next
End


' How to properly write several different variables into a bank:

Local MyBank:TBank=CreateBank(16)

PokeByte MyBank,0,$11
PokeShort MyBank,1,$1122 ' new address = 0+1=[1]
PokeInt MyBank,3,$11223344 ' new address = [1]+2=(3)
PokeLong MyBank,7,$1122334455667788 ' new address = (3)+4=7
End

EndRem


Great idea, guys!

I'm all in favor of the "Related Commands: blah blah blah" (with hyperlinks to those related commands) approach as well, as alphabetical order is not always the best way to organize commands, even within a certain BMax documentation category.

Or, alternatively or in addition to that, if slightly more complete examples are given with not-yet-learned commands included, the actual commands in the example could be hyperlinks.

For example, in CS_TBL's CreateBank() code above, BankSize() and PeekByte() could both be hyperlinked to those command definitions. The other commands, such as Local, For and Print would not need to be, as they are more general and not really closely connected to CreateBank().

Russell

The real handy part of a manual is what I've done in the lowest 3 examples.

Instead of:
<command> -> <explanation>

one learns more from:

<code problem> -> <solution1>, <solution2>, <solution3> etc.

Ok, not really a command reference, but nonetheless handy to include for beginners.
'
' six ways to iterate
'


' using For-Next
For Local t:Int=0 To 15
	Print t
Next

' using For-Step-Next 
For t=0 To 15 Step 1
	Print t
Next

' using For-Until-Next
For Local t:Int=0 Until 16
	Print t
Next

' using Repeat-Until
t=0
Repeat
	Print t
	t:+1
Until t=16


' using Repeat-Exit-Forever
t=0
Repeat
	Print t
	t:+1
	If t=16 Exit
Forever


' using While-Wend
t=0
While t<16
	Print t
	t:+1
Wend

'
' How *not* to iterate using a non-const step:
'

' using For-Step-Next 
Local a:Int=2

'For t=0 To 15 Step a ' <- will cause an error
'	Print t
'Next


'
' How to iterate using a non-const step:
'


' using Repeat-Until
a=2
t=0
Repeat
	Print t
	t:+a
Until t=16


' using Repeat-Exit-Forever
t=0
Repeat
	Print t
	t:+a
	If t=16 Exit
Forever


' using While-Wend
t=0
While t<16
	Print t
	t:+a
Wend


'
' How *not* to iterate downwards using For-Next-Step:
'

Print "------------------"

For Local b:Byte=15 To 0 Step -1
	Print t
Next

For Local c:Short=15 To 0 Step -1
	Print t
Next

' reason: these variables must be signed, which 'byte' and 'short' aren't.
End


@CS_TBL: You forgot For...until. Always useful when iterating through arrays. "For idx%=0 until foo.length"

Right, will add. Tho I've actually never used it.. :P

By the way, did I made the suggestion already to use a Wiki for this task? ;)

Jake L: There's been at least two attempts to do this with a Wiki. For this attempt I'd like to stick to this method.

CS_TBL, North: I've included your contributions to the compiled help. Download the latest version, click on the search tab and search for your name to see the examples you have contributed. Thanks

We are now at 41% complete from 30% before w contributions from CS_TBL, North & yours truly. I'm targetting 90% by year end :) Keep them coming...

As a reminder, checkout http://www.2dgamecreators.com/files/examples.htm for a list of functions without examples before contributing.

In what kind of setting/enviroment are you going to place those Howtos? Appendixes?

Rem

'
' Sin
'
' returns the sine value of a given angle (in degrees), 360 degrees represent one cyclic period.
'

Graphics 640,480

SetColor 128,128,128; DrawRect 0,240,360,1

SetColor 0,255,255

For Local t:Int=0 To 359
	Plot t,240+Sin(t)*80
Next

Flip

Repeat WaitKey() Until KeyDown(KEY_ESCAPE)
End


'
' Cos
'
' returns the cosine value of a given angle (in degrees), 360 degrees represent one cyclic period.
'

Graphics 640,480

SetColor 128,128,128; DrawRect 0,240,360,1

SetColor 0,255,255

For Local t:Int=0 To 359
	Plot t,240+Cos(t)*80
Next

Flip

Repeat WaitKey() Until KeyDown(KEY_ESCAPE)
End


'
' ATan2
'
' returns the angle in degrees between two points by giving the width and height between then.
'

Print ATan2(4,4)
'4^|    / (45 degrees)
'  |   / 
'  |  /
'  | /
'  |/
'  +-----
'       4>
End


'
' How to draw a 'dotted' circle using Sin/Cos
'
'

Graphics 640,480

Local radius:Int=80

SetColor 0,255,255

For Local t:Int=0 To 359 Step 4
	Plot 320+Sin(t)*radius, 240+Cos(t)*radius
Next

Flip

Repeat WaitKey() Until KeyDown(KEY_ESCAPE)
End

'
' How to draw a 'dotted' flower using Sin/Cos
'

Graphics 640,480

Local radius:Int

SetColor 0,255,255

For Local t:Int=0 To 359 Step 4
	radius=Sin(t*8)*40+80
	Plot 320+Sin(t)*radius, 240+Cos(t)*radius
Next

Flip

Repeat WaitKey() Until KeyDown(KEY_ESCAPE)
End

EndRem


Someone ought to write appendixes about typical design patterns, and their applications.

I was not planning for how-tos and appendices. ATM I'm sticking them in as extra link to the function example. My main objective is to have 90% of the bmx functions to have examples

How do you plan to handle examples that covers more than one function? For example, CanvasGraphics() is covered in the CreateCanvas()-example quite well.

I simply copy them across. So they will have the same example. In the stats they count as 2 examples which is OK as they represent examples for 2 functions.

This has a lot of Pixmap Functions. (Please optimize it if you can.)
'Prompt the user for an image file
FilePath$=RequestFile("Select an Image File","Image Files:png,jpg,bmp")

'Load the file into a TPixmap according to its format
Select ExtractExt(FilePath$)
	Case "png"
		Image:TPixmap=LoadPixmapPNG(FilePath)
	Case "jpg"
		Image:TPixmap=LoadPixmapJPeg(FilePath)
	Default
		Image:TPixmap=LoadPixmap(FilePath)
EndSelect

'Ensure the file loaded
If Image=Null
	Notify "The File Could Not Load. The Program Will Now End."
	End
EndIf

'Setup the window
Graphics 600,600,0,60,2

'Create a backup pixmap
ImageBackup:TPixmap=Image

'Setup variables
w=PixmapWidth(Image)
h=PixmapHeight(Image)
wspeed=w/20
hspeed=h/20

'Run the program until the user presses ESC
Repeat	
	'Respond to keypresses

		'Change pixmap size
		If KeyDown(KEY_UP) And w>wspeed Then w:-wspeed
		If KeyDown(KEY_DOWN) Then w:+wspeed
		If KeyDown(KEY_LEFT) And h>hspeed Then h:-hspeed
		If KeyDown(KEY_RIGHT) Then h:+hspeed
		Image=ResizePixmap(ImageBackup,w,h)
		
		'Change pixmap orientation
		If KeyHit(KEY_X) Then Image=XFlipPixmap(Image)
		If KeyHit(KEY_Y) Then Image=YFlipPixmap(Image)
		
		'Mask pixmap
		If KeyHit(KEY_M)
			RequestColor(128,128,128)
		EndIf
		Image=MaskPixmap(Image,RequestedRed(),RequestedGreen(),RequestedBlue())
		
		'Save pixmap
		If KeyHit(KEY_S)
			'Prompt the user for a path to save to
			FilePath$=RequestFile("Save As","PNG:png;JPG:jpg",True)
			'Save the TPixmap into a file according to its format
			Select ExtractExt(FilePath$)
				Case "png"
					SavePixmapPNG(Image,FilePath)
				Case "jpg"
					SavePixmapJPeg(Image,FilePath)
			EndSelect					
		EndIf
		
	'Draw the pixmap to the buffer
	DrawPixmap Image,0,0
	
	'Display Information
	SetColor 255,0,0
	DrawText "Image Width:"+PixmapWidth(Image)+"  Image Height:"+PixmapHeight(Image),0,0 
	
	'Show the buffer and clear it for the next round
	Flip
	Cls
	
Until KeyHit(KEY_ESCAPE)


hm.. isn't that a bit much for examples which are to explain one single thing?

CASO, thanks for your contributions. I broke your example down into smaller slices on a per function basis. Do a search on CASO to check them out.

We have now reached an important milestone, 45% functions with examples, which is halfway towards my stated target of 90% done by year end :)

Check out the download page in the top post.

Can we keep the (forum-)jokes? :P

Rem
'
' Banksize
'
' returns the size (in bytes) of a bank
'

Local bank:TBank=CreateBank( 10 + Rnd(40) )

Print "size of the bank is: "+BankSize(bank)

End
'
' Debuglog
'
' When running in debugmode, Debuglog prints given strings in the same tab where Print outputs to.
'

DebugLog "My debug text"


'
' Debugstop
'
' Debugstop halts program execution and offers you to inspect your variables as they were at the moment of halting
'


Graphics 640,480
Local a:Int

Repeat
	a=Rnd(20)
Until KeyDown(KEY_ESCAPE)
DebugStop




'
' Ceil
'
' Gives the integer value of a given value at the "ceiling" of that value.
'

For Local t:Int=-31 To 31
Print "real value: "+t/10.0+" Ceil value: "+Ceil(Double(t/10.0))
Next
End


'
' Floor
'
' Gives the integer value of a given value at the "floor" of that value.
'

For Local t:Int=-31 To 31
Print "real value: "+t/10.0+" Floor value: "+Floor(Double(t/10.0))
Next
End



'
' A practical example of Ceil and Floor
'

Graphics 640,480
Local x:Int,y:Int
Local mx:Int,my:Int

HideMouse
Repeat
	mx=MouseX()
	my=MouseY()
	
	Cls
	' draw grid
	SetColor 90,90,90
	For y=0 Until 480 Step 20
		For x=0 Until 640 Step 20
			Plot x,y
		Next
	Next
	
	'draw mouse mx,my
	SetColor 255,255,255
	DrawRect mx-1,my-1,3,3
	
	' draw ceiled and floored mouse mx,my
	SetColor 255,255,0
	DrawRect Ceil( mx/20.0)*20-1,Ceil(my/20.0)*20-1,3,3
	
	SetColor 0,255,255
	DrawRect Floor(mx/20.0)*20-1,Floor( my/20.0)*20-1,3,3
	
	Flip
	
Until KeyDown(KEY_ESCAPE)
End




'
' GadgetX(gadget)
'
' Gives the X coordinate of a given gadget
'

'
' GadgetY(gadget)
'
' Gives the Y coordinate of a given gadget
'

'
' GadgetWidth(gadget)
'
' Gives the width of a given gadget
'

'
' GadgetHeighth(gadget)
'
' Gives the height of a given gadget
'

Local window:tgadget=CreateWindow("example",16,0,320,240)
Local label:tgadget=CreateLabel("",4,4,160,30,window)

SetGadgetText label,GadgetX(window)+" "+GadgetY(window)+" "+GadgetWidth(window)+" "+GadgetHeight(window)
Repeat
	WaitEvent();If EventID()=EVENT_WINDOWCLOSE End
Forever


'
' Hex(value)
'
' Hex gives the hexademimal string of a given value, with a 'width' of 8 digits, being the 4 bytes of the given int value.
'

For Local t:Int=0 To 255
	If Not(t Mod 16) Print
	Print "decimal: "+RSet(t,3)+" | hex: "+Hex(t)
Next
End


'
' ImageWidth(image)
'
' Gives the width of an image.
'

Local myimage:Timage=CreateImage(64,32)
Print ImageWidth(myimage)
End

'
' ImageHeight(image)
'
' Gives the height of an image.
'

Local myimage:Timage=CreateImage(64,32)
Print ImageHeight(myimage)
End

	
'
' Instr
'
' Returns the position in a given string where a given substring can be found. It returns 0 when the substring
' is not found. This can typically be used to check whether a substring is present at all, as a given offset represents
' True.
' 

Local mystring$="*sniffage*, I need more media!"

' check for the position
Print Instr(mystring,"more")

If Instr(mystring,"new PC") Print "large!"
If Not Instr(mystring,"new PC") Print "*sniff*"

If Instr(mystring,"media") Print "large!"

End


'
' Lower(string)
'
' Returns the given string in lower-case.
'

Print Lower("abcdEFGH")
End


'
' Max(a,b)
'
' Returns the biggest of the two given values
'

Print Max( 1,10 )
Print Max( Max(1,10), Max(-50,-5) )
End


'
' Min(a,b)
'
' Returns the smallest of the two given values
'

Print Min(99,9 )
Print Min( Min(-1,-10), Min(-50,-5) )
End

'
' Mid(str$,pos,size=-1)
'
' Returns a section of the given string, note that the pos arguement is one-based, not zero-based.
'

Local a$="abcd1234efgh"
Print Mid(a,5,4)
End


'
' Left(str$,n)
'
' Prints the most left n characters from the given string
'

Print Left("12345678",4)
End

'
' Right(str$,n)
'
' Prints the most right n characters from the given string
'

Print Right("12345678",4)
End


'
' LSet(str$,n)
'
' Changes the length of a string. If the originel string was longer then n characters from the left are used. If the new
' length is longer than the originel length, spaces are added right from the original string.

Print LSet("12345678",3)
Print "["+LSet("12345678",10)+"]"
End

'
' RSet(str$,n)
'
' Changes the length of a string. If the originel string was longer then n characters from the right are used. If the new
' length is longer than the originel length, spaces are added left from the original string.

Print RSet("12345678",3)
Print "["+RSet("12345678",10)+"]"
End

EndRem


Here are some more.
'GetColor()
Graphics 640,480
Local Red,Green,Blue
SetColor Rnd(255),Rnd(255),Rnd(255)
GetColor(Red,Green,Blue)
DrawText "Red: "+Red+"  Green: "+Green+"  Blue: "+Blue , 10 , 10
Flip
WaitKey()
End

'SetAlpha()/GetAlpha()
Graphics 640,480
SetBlend ALPHABLEND
Repeat 
	SetAlpha(Rnd(0,1))
	Alpha#=GetAlpha()
	DrawOval 270,190,100,100
	SetAlpha(1)
	DrawText "Alpha: "+Alpha , 10 , 10
	Delay 500
	Flip
	Cls
Until KeyHit(key_escape) Or AppTerminate()
End

'GetBlend()
Graphics 640,480
SetBlend ALPHABLEND '<- Set to Any ONE Blend Mode
Select GetBlend()
	Case ALPHABLEND
		DrawText "AlphaBlend is On" , 10 , 10
	Case LIGHTBLEND
		DrawText "LightBlend is On" , 10 , 10
	Case MASKBLEND
		DrawText "MaskBlend is On" , 10 , 10
	Case SOLIDBLEND
		DrawText "SolidBlend is On" , 10 , 10
EndSelect
Flip
WaitKey()
End

'GetOrigin()
Graphics 640,480
SetOrigin Rnd(640),Rnd(480)
Local OriginX#,OriginY#
GetOrigin(OriginX,OriginY) 
DrawText "Origin: "+OriginX+" , "+OriginY, 0 , 0
Flip
WaitKey()
End

'GetScale()
Graphics 640,480
SetScale Rnd(0.5,2),Rnd(0.5,2)
DrawOval 270,190,100,100
Local ScaleX#,ScaleY#
GetScale(ScaleX,ScaleY) 
SetScale 1,1
DrawText "Scale: "+ScaleX+" , "+ScaleY, 10 , 10
Flip
WaitKey()
End

'GetRotation()
Graphics 640,480
SetScale 1.5,1.5
SetRotation Rnd(360) 
DrawText "Rotation: "+GetRotation(), 320 , 240
Flip
WaitKey()
End

'GetLineWidth()
Graphics 640,480
SetLineWidth Rnd(10) 
DrawLine 0,0,640,480
DrawText "Line Width: "+GetLineWidth(), 10 , 10
Flip
WaitKey()
End

'HideMouse()/ShowMouse()
Graphics 640,480
Repeat
DrawText "Press Space to Hide/Show Cursor", 10 , 10
If KeyHit(key_space)
	If Hide=True
		Hide=False
		ShowMouse()
	Else
		Hide=True
		HideMouse()
	EndIf
EndIf
Flip
Cls
Until KeyHit(key_escape) Or AppTerminate()
End

'MoveMouse()
Graphics 640,480
Repeat
DrawText "Press Space to Move Cursor to the Middle of the Window", 10 , 10
If KeyHit(key_space) Then MoveMouse(320,240)
Flip
Cls
Until KeyHit(key_escape) Or AppTerminate()
End

'Replace()
Str$="This is a test of the Replace command."
Print "Original: "+Str
Str=Replace(Str,"e","*")
Print "Altered: "+Str

'HideGadget()/ShowGadget()
win=CreateWindow("HideGadget()/ShowGadget()",0,0,300,300,Null,WINDOW_TITLEBAR|INDOW_CLIENTCOORDS)
button=CreateButton("Hide/Show",0,0,300,30,win)
panel=CreatePanel(25,50,250,200,win,PANEL_BORDER) 
Repeat
WaitEvent()
If EventSourceHandle()=button
	If Hide=True
		Hide=False
		ShowGadget(panel)
	Else
		Hide=True
		HideGadget(panel)
	EndIf
EndIf
Until EventID()=EVENT_WINDOWCLOSE
End

'Desktop()
Print "Desktop Width: "+GadgetWidth(Desktop())+"  Desktop Height: "+GadgetHeight(Desktop())

'GraphicsWidth()\GraphicsHeight()\GraphicsDepth()\GraphicsHertz()
Graphics 640,480,32,60
DrawText "Graphics Width: "+GraphicsWidth(), 10 , 10
DrawText "Graphics Height: "+GraphicsHeight(), 10 , 30
DrawText "Graphics Depth: "+GraphicsDepth(), 10 , 50
DrawText "Graphics Hertz: "+GraphicsHertz(), 10 , 70
Flip
WaitKey()
End


More than 50% of functions now have at least one example.
The latest version can be downloaded from http://www.2dgamecreators.com/files/

Next milestone is to surpass BRL no of examples, this effort has contributed examples to 164 functions cf BRL's 190.

Don't forget to check the list at http://www.2dgamecreators.com/files/examples.htm before contributing.

Here are a few more.
'WaitKey()
Graphics 640,480
DrawText "Press any key to end this program.", 10 , 10
Flip
WaitKey()
End

'MenuChecked()/CheckMenu()/UncheckMenu()
win=CreateWindow("MenuChecked()/CheckMenu()/UncheckMenu()",0,0,400,200)
mainmenu=WindowMenu(win)
menu=CreateMenu("Menu",101,mainmenu)
menuitem=CreateMenu("Menu Item",102,menu)
UpdateWindowMenu(win)
Repeat
	WaitEvent()
	If EventSourceHandle()=menuitem
		If MenuChecked(menuitem) Then UncheckMenu(menuitem) Else CheckMenu(menuitem)
		UpdateWindowMenu(win)
	EndIf
Until EventID()=EVENT_WINDOWCLOSE
End

'MaximizeWindow()/MinimizeWindow()/RestoreWindow()/WindowMaximized()
win=CreateWindow("MaximizeWindow()/MinimizeWindow()/RestoreWindow()/WindowMaximized()",0,0,300,300)
minbutton=CreateButton("Minimize",0,0,150,30,win)
maxbutton=CreateButton("Maximize/Restore",150,0,150,30,win) 
Repeat
	WaitEvent()
	If EventSourceHandle()=minbutton Then MinimizeWindow(win)
	If EventSourceHandle()=maxbutton
		If WindowMaximized(win)
			RestoreWindow(win)
		Else
			MaximizeWindow(win)
		EndIf
	EndIf
Until EventID()=EVENT_WINDOWCLOSE
End

'TileImage()
Graphics 640,480
image=LoadImage(BlitzMaxPath()+"\samples\hitoro\gfx\boing.png")
Repeat
	TileImage(image,MouseX(),MouseY())
	Flip
	Cls
Until KeyHit(key_escape) Or AppTerminate()
End

'MilliSecs()
start=MilliSecs()
Input("Type Anything >")
Print "You took "+(MilliSecs()-start)+" milliseconds to type that."
End

'Delay()
Print "This is a test line."
Delay 3000
Print "This line was printed 3000 milliseconds later."
Print "This program will end in 2000 milliseconds."
Delay 2000
End

'MenuEnabled()/EnableMenu()/DisableMenu()
win=CreateWindow("MenuEnabled()/EnableMenu()/DisableMenu()",0,0,400,200)
mainmenu=WindowMenu(win)
menu=CreateMenu("Menu",101,mainmenu)
menuitem=CreateMenu("Press This",102,menu)
menuitem2=CreateMenu("Watch This",103,menu)
UpdateWindowMenu(win)
Repeat
	WaitEvent()
	If EventSourceHandle()=menuitem
		If MenuEnabled(menuitem2) Then DisableMenu(menuitem2) Else EnableMenu(menuitem2)
		UpdateWindowMenu(win)
	EndIf
Until EventID()=EVENT_WINDOWCLOSE


caso: I highly doubt your examples are 100% perfect for a manual tho. Not superstrict compliant, and uhm.. "EventSourceHandle" ?? :P

The use of Superstrict might not be mandatory, but I actually think it's best to teach things the right way. Esp. for beginners, Superstrict helps finding bugs. (also for the medium/advanced :P)

some alternatives:
SuperStrict
Rem

'
' EventSource()
'
' Gives the object where an event has been emitted from.
'

Local window:tgadget=CreateWindow("events",0,0,320,240)

Local button1:tgadget=CreateButton("Button1",4,4,80,24,window)
Local button2:tgadget=CreateButton("Button2",84,4,80,24,window)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	Select EventSource()
		Case button1 Print "button1"
		Case button2 Print "button2"
	End Select
	
Forever

'
' EventId()
'
' Gives the ID of the event that has just been emitted.
'

Local window:tgadget=CreateWindow("events",0,0,320,240)

Local button:tgadget=CreateButton("Button1",4,4,80,24,window)
Local canvas:tgadget=CreateCanvas(84,4,80,24,window,1)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	Select EventID()
		Case EVENT_GADGETACTION Print "gadgetaction (buttonpress, etc.)"
		Case EVENT_MOUSEMOVE Print "canvas mousemove"
	End Select
	
Forever

'
' EventData()
'
' Gives the data field (an int value) of the event that has just been emitted.
'

Local window:tgadget=CreateWindow("leftclick/rightclick",0,0,320,240)

Local canvas:tgadget=CreateCanvas(4,4,160,160,window,1)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	Select EventData()
		Case 1 Print "leftclick"
		Case 2 Print "rightclick"
	End Select
Forever


'
' EventX()
'
' Gives the X field (an int value) of the event that has just been emitted.
'

Local window:tgadget=CreateWindow("move mouse",0,0,320,240)

Local canvas:tgadget=CreateCanvas(4,4,160,160,window,1)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	If EventID()=EVENT_MOUSEMOVE
		Print EventX()
	EndIf
Forever


'
' EventY()
'
' Gives the Y field (an int value) of the event that has just been emitted.
'

Local window:tgadget=CreateWindow("move mouse",0,0,320,240)

Local canvas:tgadget=CreateCanvas(4,4,160,160,window,1)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	If EventID()=EVENT_MOUSEMOVE
		Print EventY()
	EndIf
Forever


'
' EventText$()
'
' Gives the text$ field (converted from the EXTRA field) of the event that has just been emitted.
'

Local window:tgadget=CreateWindow("move mouse",0,0,320,240,Null,15|WINDOW_ACCEPTFILES)

Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
	
	If EventID()=EVENT_WINDOWACCEPT
		Print EventText()
	EndIf
Forever

EndRem


New milestone reached. User examples has surpassed BRL examples.

I have now added methods to the list instead of just functions so there's more to do but we are still above 50%

The latest version can be downloaded from www.2dgamecreators.com/files/

Thanks Assari!

Jason

Another milestone reached, 60% of functions/methods now with examples. I will plod through and add more examples but will not be bumping this thread until the next milestone of 70% which could take the next 4-5 weeks.

As I add stuff, I will upload to the website so that downloads will be up to date eventhough there's no news here.

If you wish to contribute, don't forget to check http://www.2dgamecreators.com/files/examples.htm to see which functions/methods are still without examples.