Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --os.loadAPI("theinsekt/turtle2")
- -- TODO: Change so that multiple positions can be used.
- -- this can implemented by not using these local variables and
- -- instead working on a position table.
- -- Then a new table can be created and changed independently
- -- of the old one.
- x=0 -- forward, back
- y=0 -- up, down
- z=0 -- right, left (not turn)
- rot=0 -- direction/rotation the turtle is facing
- -- this can be used to make sure
- -- the turtle isn't outside a
- -- cube of a certain size
- function getLargest()
- -- make local copies of the coordinates
- -- but use the absolute value
- local x=math.abs(x)
- local y=math.abs(y)
- local z=math.abs(z)
- if x>y then
- if x>z then
- return x
- else
- return z
- end
- else
- if y>z then
- return y
- else
- return z
- end
- end
- end
- function printit()
- print("before: "..x.." "..y.." "..z.." "..rot)
- end
- function reset()
- x=0
- y=0
- z=0
- rot=0
- end
- -- put function in the table
- horzT={
- [0]=function(length)
- x=x+length
- end,
- [1]=function(length)
- z=z+length
- end,
- [2]=function(length)
- x=x-length
- end,
- [3]=function(length)
- z=z-length
- end,
- }
- -- table that can update the coordinates
- -- if you go a given length in the
- -- in a direction
- updateT={
- f=function(length)
- horzT[rot](length)
- end,
- b=function(length)
- horzT[rot](length)
- end,
- u=function(length)
- y=y+length
- end,
- d=function(length)
- y=y-length
- end,
- r=function(length)
- rot=(rot+length)%4
- end,
- l=function(length)
- rot=(rot-length)%4
- end,
- }
- -- updates the position values
- -- given the input values
- -- returns nil
- function update(dir, length)
- --print("before: "..x.." "..y.." "..z.." "..rot)
- --print(dir.." "..length)
- updateT[dir](length)
- --print("after: "..x.." "..y.." "..z.." "..rot)
- end
- function whatIf(dir, length)
- update(dir,length)
- local a, b, c, d=get()
- update(dir,-length)
- return a,b,c,d
- end
- function whatIfLargest(dir, length)
- update(dir,length)
- local res=getLargest()
- --print(x.." "..y.." "..z" "..rot)
- update(dir,-length)
- return res
- end
- -- returns the position values
- -- x,y,z,rot
- function get()
- return x, y, z, rot
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement