I would like to have some way that you could use a read() or similar input method and have a turtle use it like it was in the lua interpreter. I'm not using read() I'm actually using chat(message) from misc peripherals. I would like to be able to give this turtle commands like I was in lua.
Read() As Lua
Started by CCJJSax, Aug 31 2013 04:18 PM
1 reply to this topic
#1
Posted 31 August 2013 - 04:18 PM
#2
Posted 31 August 2013 - 04:24 PM
You can run lua commands using loadstring(). loadstring() returns a function, which you can call to then run the specified string.
If you want to run a string without crashing, use pcall().
pcall() returns true or false, whether the function ran successfully or not. If ok is false, err is the error message.
local cmd = "print('Hello world!')"
local func = loadstring(cmd)
func() --> Hello world!
If you want to run a string without crashing, use pcall().
local ok, err = pcall(func) if not ok then print(err) end
pcall() returns true or false, whether the function ran successfully or not. If ok is false, err is the error message.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











