This section is intentionally detailed. Read each concept, then run the example. Learning is faster when you test small pieces one by one.
A program works with values. A type tells LunarBasic what kind of value each variable can hold.
0, -5, 42).1.5, 3.14159).True or False."Hello").Dim score As Integer
Dim speed As Float
Dim isAlive As Boolean
Dim playerName As String
score = 10
speed = 2.5
isAlive = True
playerName = "Luna"
Assignment stores a value in a variable.
Dim health As Integer
health = 100
health = health - 25
After the second assignment, health becomes 75.
Dim total As Integer
Dim base As Integer
Dim bonus As Integer
base = 50
bonus = 20
total = (base + bonus) * 2
Expressions can combine numbers, variables, and operators.
Dim score As Integer
score = 85
If score >= 100 Then
DebugPrint("Perfect")
ElseIf score >= 60 Then
DebugPrint("Pass")
Else
DebugPrint("Try again")
End If
Dim i As Integer
For i = 1 To 5
DebugPrint("Count: " + Str(i))
Next
Dim x As Integer
x = 0
While x < 3
DebugPrint("x=" + Str(x))
x = x + 1
Wend
Sub performs work. Function performs work and returns a value.
Sub PrintGreeting(name As String)
DebugPrint("Hello, " + name)
End Sub
Function Add(a As Integer, b As Integer) As Integer
Return a + b
End Function
Dim result As Integer
PrintGreeting("Luna")
result = Add(3, 4)
Dim points(5) As Integer
points[0] = 10
points[1] = 20
points[2] = 30
DebugPrint("First point: " + Str(points[0]))
Dim firstName As String
Dim message As String
firstName = "Ari"
message = "Welcome, " + firstName
DebugPrint(message)
SetAppTitle("Fundamentals Demo")
Graphics(800, 600, False)
SetClsColor(12, 18, 28)
Dim running As Boolean
Dim fontRef As Integer
Dim x As Integer
fontRef = LoadFont("", 20)
running = True
x = 50
Do
If KeyDown(KEY_RIGHT) Then x = x + 3
If KeyDown(KEY_LEFT) Then x = x - 3
Cls()
DrawText(fontRef, x, 40, "Move with LEFT/RIGHT. ESC exits.")
Flip()
If KeyHit(KEY_ESC) Then
running = False
End If
Loop Until Not running
FreeFont(fontRef)
End If, Next, or Wend. Fix: write closing lines immediately.Navigation: Previous: Complete IDE Guide | Outline | Next: Game Development Concepts