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

[Solved]Lua - unexepected symbol using assert(loadstring)

Started by kMoney6231, 28 July 2012 - 03:38 PM
kMoney6231 #1
Posted 28 July 2012 - 05:38 PM
Hi, everyone! I was hoping if someone could give me a hand with this code, Im trying to send commands remotely via a "Master" computer to specific computers in my factory, however I've hit a snag and cant seem to fix it, I believe the error is somewhere withing my os.pullEvent(), without loadstring I can get it to say Completed, but as soon as i add it, the code gives me:

eListen:7: [string "string"]:1: unexpected symbol

and I've based all of this off of http://www.computerc...ands-over-wifi/

Also, is it even possible to send a computer a command and have it run a program? or can you just send text.


Here is the program for what i've dubbed the Master computer
http://pastebin.com/p93TGXAZ

term.setCursorPos(1,1)
  -- Check if Modem is On
	 if rednet.open("right") == true then
	  print("kNet is open already!")
else
rednet.open("right")
print("kNet is Online!")
end
term.clear()
while true do
term.setCursorPos(1,1)
print("What Computer are Communicating with?\n")
print("88: Engine Controller\n90: Factory Controller\n105:Unknown")
local id = tonumber(io.read()) -- Get ID from LIST
os.sleep(.8)
term.clear()
term.setCursorPos(1,1)
print("You've Chosen Computer ", id, " Give it a Command!")
local command = tostring(io.read())
print("Sending Command!")
rednet.send(id, command)
local event, param1 = os.pullEvent("rednet_message")
if param1 == true then
print("Success!")
end
end

http://pastebin.com/x5n1u5pm
I dont really hate lua, that was out of debugging frustration lol.

rednet.open("back")
print("Computer is Listening")
command = os.pullEvent
while true do
local id, msg, dt = os.pullEvent("rednet_message")
if id == "rednet_message" then
assert (loadstring(msg))
print("Completed!")
else
print("I fucking hate lua")
end
end 
kMoney6231 #2
Posted 29 July 2012 - 05:01 PM
Not sure If I should make a new post or edit. But I've found a solution! I completely dropped the os.pullEvent() and loadstring to use rednet.recieve() and shell.run() which is weird because, rednet.recieve() gives me attempt to call nil, but after i delete the line and retype it works, but that's beside the point. here's the code if anyone wants to see it:


term.setCursorPos(1,1)
-- Check if Modem is On
if rednet.open("right") == true then
print("kNet is open already!")
else
rednet.open("right")
print("kNet is Online!")
end
term.clear()
while true do 
term.setCursorPos(1,1)
print("What Computer are Communicating with?n")
print("88: Engine Controllern90: Factory Controllern105:Zach Eats Ass Controller")
local id = tonumber(io.read()) -- Get ID from LIST
os.sleep(.8)
term.clear()
term.setCursorPos(1,1)
print("You've Chosen Computer ", id, " Give it a Command!")
local command = tostring(io.read())
print("Sending Command!")
rednet.send(id, command)
Id, msg = rednet.receive()
print (msg)
end

Listening Program:


rednet.open("back")
print("Computer is Listening")
 Id, msg = rednet.receive()
  shell.run(msg)

Also, I would still like to know how i can use loadstring effectively if anyone could enlighten me it would be great!