This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
qwerty's profile picture

[SOLVED]propper use of unserialize to run functions?

Started by qwerty, 23 February 2020 - 10:43 AM
qwerty #1
Posted 23 February 2020 - 11:43 AM
A new problem I've run into is: how do I run scripts that have been unserialized.

I understand how
textutils.unserialize()
works, how ever my issue is that, not only do I not know how to pass commands to the lua prompt, but also the problem that when calling
tempvar()
it trhows a nill error, but it prints just fine.

I'm using plethora's chat recorder with the standard script running code but slightly altered to run the lua code entered in chat.
the original plethora's code found here
(It's the third code snippet)

and my code that I'm using-


--[[irrelevant code

local function clear()
  term.clear()
  term.setCursorPos(1,1)
end

clear()
--]]

local chat = peripheral.wrap("right")

while true do

--message catching
  local _, player, message, uuid = os.pullEvent("chat_message")

--message parsing
  local tempmsg = string.sub(message,2)
  tempvar = textutils.unserialize(tempmsg)

--debug
  print(message)
  print(tempmsg)
  print(tempvar) --pre edit: print(tempmsg)

--atempted function call
  tempvar()

end


With regards
-qwerty
Edited on 25 February 2020 - 07:43 AM
Lupus590 #2
Posted 23 February 2020 - 02:27 PM
you want loadstring not textutils.unserialise, functions and coroutines can't be serialised in the version of lua that CC has.
qwerty #3
Posted 24 February 2020 - 09:26 AM
you want loadstring not textutils.unserialise…
Thanks man! woorks like a charm now!