Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
local robot=require("robot")
function act(action)
local actions={
f=robot.forward,
b=robot.back,
u=robot.up,
d=robot.down,
l=robot.turnLeft,
r=robot.turnRight,
ta=robot.turnAround,
sw=robot.swing,
su=robot.swingUp,
sd=robot.swingDown,
ul=robot.use,
uu=robot.useUp,
ud=robot.useDown,
dt=robot.detect,
du=robot.detectUp,
dd=robot.detectDown
}
for doaction in string.gmatch(action,"%.%d*%a+") do
local quantity=string.match(doaction,"%d+")
if quantity==nil then
quantity="1"
end
local direction=string.match(doaction,"%a+")
print (doaction," ",quantity," ",direction)
for i=1,quantity do
actions[direction]()
end
end
end
return act
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more