Examples - AdamClements/Imprint GitHub Wiki
# A robot which flips between its starting location
# and 10,-10 squares to the northeast
LET dest
LET orig
# Store original position
GetPos
PopTo orig
# Calculate a new position 10,-10 to the northeast
PushFrom orig
VecAdd (10,10)
PopTo dest
# Now start trying to get to one then back to the other
# in a loop
to-dest:
GetPos
PushFrom dest
JumpEq to-orig
# Still here? Mustn't be there yet, try moving
# then loop back
SetColour 0xff0000
PushFrom dest
MoveTo
Jump to-dest
to-orig:
GetPos
PushFrom orig
JumpEq to-dest
# Still here? Mustn't be there yet, try moving
# then loop back
SetColour 0x00ff00
PushFrom orig
MoveTo
Jump to-orig
# This bot moves randomly
CONST TICKS-TO-CHANGE 10 # How many ticks to wait before changing
# direction
change-direction:
Random 11
Random 11
VecComp
VecSub (5, 5) # Get a random vector between (-5, -5
GetPos
VecAdd # Make it relative to my position
MoveTo # Go there
Push 0 #Initialise the wait count
start:
Add 1 # Increment the wait counter
Clone # Keep a copy for the next loop
Push TICKS-TO-CHANGE
JumpLt start # Jump if waited < TICKS-TO-CHANGE
Pop # Get rid of the counter off the stack
Jump change-direction
CONST PASSWORD 432
# Say our ID is 41 and we want to move to (5,5), we would expect a message
# in the form:
# 41 432 (5,5)
# and the following chunk of memory will store incoming messages while we
# check for that format
LET msgbuffer[3]
# Listen for messages on channel 12
MessageSetChannel 12
## Messaging loop, check for new orders
start:
MessageRead msgbuffer 3
JumpZero start
PushFrom msgbuffer[0]
GetId
JumpNe start
PushFrom msgbuffer[1]
Push PASSWORD
JumpNe start
move:
PushFrom msgbuffer[2]
MoveTo
Jump start
A self-building wall
CONST DIRECTION (0,-1)
LET parts[2] 8086 8110
program:
FactoryOrderParts parts 2
FactoryFlashFirmware program 23
GetPos
VecAdd DIRECTION
FactoryBuild
SetColour 0xff0000
start:
# Do other things
Jump start
Or you can use the just-compile button to LET a different program into your data space and build a unit using that