Skip to content

Functions

Nicolas Maitre edited this page Jan 20, 2021 · 10 revisions

ProgCraft programs are written in vanilla Ruby so most features are available. Ruby documentation

Functions for the movement

walk_forward

Call : walk_forward()
Effect : Move Robert one square in front of him
Input : any
Return : any

# Example : Move Robert by 4 squares
walk_forward()
walk_forward()
walk_forward()
walk_forward()

turn_right

Call : turn_right()
Effect : Rotate Robert to his right
Input : any
Return : any

# Example : Turn around
turn_right()
turn_right()

turn_left

Call : turn_left()
Effect : Rotate Robert to his left
Input : any
Return : any

# Example : Turn around
turn_left()
turn_left()

gps_x

Call : gps_x()
Effect : any
Input : any
Return : Robert's x position in integer

# Example : Say Robert's position
posx = gps_x()
say("Robert x position is : #{posx}")

gps_y

Call : gps_y()
Effect : any
Input : any
Return : Robert's y position in integer

# Example : Say Robert's position
posy = gps_y()
say("Robert x position is : #{posy}")

is_clear_path

Call : is_clear_path()
Effect : any
Input : any
Return : true if the square in front of Robert can be crossed, otherwise returns false

# Example : Move forward while path in front is clear
while(is_clear_path() == true)
    walk_forward()
end

is_clear_right

Call : is_clear_right()
Effect : any
Input : any
Return : true if the square in right of Robert can be crossed, otherwise returns false

# Example : Turn right if path is clear
if(is_clear_right() == true)
    turn_right()
end

is_clear_left

Call : is_clear_left()
Effect : any
Input : any
Return : true if the square in right of Robert can be crossed, otherwise returns false

# Example : Turn left if path is clear
if(is_clear_left() == true)
    turn_left()
end

compass

Call : compass()
Effect : any
Input : any
Return : Robert's direction. Possible values are north, south, west or east

# Example : Say Robert direction
say("Robert look at #{compass()}")

Functions for interractions

ask

Call : ask(String)
Effect : Robert ask a text to user by WhatsArbre
Input : String
Return : any

# Example : Robert ask and say your name
firstname = ask("What is your name ?")
say("Hello #{firstname}")

ask_number

Call : ask_number(String)
Effect : Robert ask a number to user by WhatsArbre
Input : String
Return : any

# Example : Robert ask how many step do you want that he does
step = ask_number("How many step do you want ?")
while(step >= 0)
    walk_forward()
    step -= 1
end

say

Call : say(String)
Effect : Robert say something by WhatsArbre
Input : any
Return : String

# Example  : Robert greets you
firstname = ask("What is your name ?")
say("Hello #{firstname}")

detection

Call : detection()
Effect : Return what is under Robert
Input : any
Return : String name of object

# Example : Take if Robert is on an apple 
if(detection() == "Apple")
    take()
end

take

Call : take()
Effect : Robert takes the object under him if there is one
Input : any
Return : any

# Example : Take if Robert is on an apple 
if(detection == "Apple")
    take()
end

drop

Call : drop()
Effect : Robert drops the last object added to his inventory
Input : any
Return : any

# Example : Drop a number of items asked by player
count = ask_number(`How many object do you want drop ?`)
while(step >= 0)
    drop()
    walk_forward()
end

Clone this wiki locally