Repository navigation
Experimental Language Features
score = 0
score += 10
score -= 3
score *= 2
score /= 7
DebugLog score ; 2
mask = 255
mask &= 15
DebugLog mask ; 15
Shorthand for x = x + 1, etc. Works on variables, fields, and array/vector elements.
n = 0
Do
n += 1
DebugLog n
Loop While n < 5
Runs the body first, then checks the condition. Loop Until works the same way but stops when the condition becomes true instead of false.
n = 10
Do
n -= 1
Loop Until n = 0
Do with no condition loops forever until an Exit.
Type Player
Field hp%
Field name$
End Type
p.Player = New Player
With p
.hp = 100
.name = "Hero"
DebugLog .name + " has " + .hp + " hp" ; Hero has 100 hp
End With
Inside the block, .field resolves against p without you having to repeat the variable name.
If enemy Is Null Then DebugLog "no enemy"
If target IsNot player Then DebugLog "not the player"
Aliases for = and <>.
Select score
Case 100
DebugLog "perfect"
Case Else
DebugLog "keep trying"
End Select
Alias for Default inside a Select block.
total = 1 + 2 + _
3 + 4
DebugLog total ; 10
A trailing underscore joins a line with the next one before parsing.
Local don't_panic% = 1
DebugLog don't_panic% ; 1
Identifiers can contain an apostrophe.
Function OnClick(x%, y%)
DebugLog "Clicked at " + x% + "," + y%
End Function
Global handler%(Int, Int) = %OnClick
handler(10, 20) ; Clicked at 10,20
%FuncName gives you a typed pointer to a function. A variable, field, or parameter can hold one by tagging it with a return type sigil (%, #, $, or @) followed by the parameter types in parentheses, e.g. %(Int, Int), #(Float), or %().
Function ForEachItem(callback%(Int))
For i = 0 To 4
callback(i)
Next
End Function
Function PrintItem(n%)
DebugLog n%
End Function
ForEachItem(%PrintItem) ; 0 1 2 3 4
Pass one in as a parameter for callbacks and dispatch tables, instead of a giant Select/Case on an int id.
Parameter types have to match the target function exactly, return type included, or it's a compile error. An untagged parameter defaults to Int. A function pointer can also live in a plain Int or Pointer (@), useful for storing one in an array. %FuncName won't work on an overloaded function name so give it something unique instead.
blitz blitz blitz