This section explains more advanced programming concepts like loops, conditionals, variables, and functions.
Loops allow you to repeat a set of instructions multiple times. KodeVR provides the following loop blocks:
// Example of a Repeat loop
repeat 4 times {
moveForward(100)
turnRight(90)
}
// This creates a square path
Conditionals allow you to execute different instructions based on certain conditions. KodeVR provides the following conditional blocks:
// Example of an If-Then-Else conditional
if (getDistance() < 50) {
// If an obstacle is detected less than 50 units away
turnRight(90)
} else {
// If no obstacle is detected
moveForward(100)
}
Variables allow you to store and manipulate data in your program. KodeVR provides the following variable blocks:
// Example of using variables
set distance to getDistance()
set heading to getHeading()
if (distance < 50) {
turnRight(90)
} else {
moveForward(distance / 2)
}
Functions allow you to create reusable blocks of code. KodeVR provides the following function blocks:
// Example of defining and calling a function
define makeSquare(size) {
repeat 4 times {
moveForward(size)
turnRight(90)
}
}
// Call the function
makeSquare(100)
makeSquare(50)