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

rednet:344: positive number expected

Started by ComputerCraftFan11, 24 March 2012 - 06:10 AM
ComputerCraftFan11 #1
Posted 24 March 2012 - 07:10 AM

term.clear()
term.setCursorPos(1,1)
local ChatType = 0;
local HostName = 0;
local HostedName = os.getComputerID();
print("Modifier's Chat Program")
print("Choose one:")
print("[1] Host")
print("[2] Join")
function host()
term.clear()
term.setCursorPos(1,1)
print("Host id: " ..HostedName)

id, message = rednet.receive()

if message == "Reload" then
  rednet.send(id, "fart")
elseif message == "has joined!" then
  rednet.send(id, id.. " has joined!")
else
  rednet.send(id, "<" ..id.. "> " ..message)
end

host()
end
while true do
local e,key = os.pullEvent( "key" )
  if key == 2 then
   ChatType = 1
   host()
  elseif key == 3 then
   ChatType = 2
   break
  end
end
function drawScreen()
term.clear()
term.setCursorPos(1,1)
rednet.send(HostName, "has joined!")
id, message = rednet.receive()
print(message)
end
function options()
term.clear()
term.setCursorPos(1,1)
write("Please enter a host id: ")
idddd = read()
HostName = idddd
drawScreen()
end
options()

It's not telling me where the error is, it just says there is a error. Help?
Casper7526 #2
Posted 24 March 2012 - 08:33 AM
It doesn't run at all and doesn't give you the line number?

Btw, your pull event won't work, the key event returns keycodes, not char's


local e,key = os.pullEvent( "key" )
if key == 2 then

This won't trigger when you press 2

local e, key = os.pullEvent("char")
if key == "2" then

That will
ComputerCraftFan11 #3
Posted 24 March 2012 - 08:35 AM
It doesn't run at all and doesn't give you the line number?

Btw, your pull event won't work, the key event returns keycodes, not char's


local e,key = os.pullEvent( "key" )
if key == 2 then

This won't trigger when you press 2

local e, key = os.pullEvent("char")
if key == "2" then

That will

It does run but it doesn't give me a line number. my pull event did work. It said its a problem in rednet
PatriotBob #4
Posted 24 March 2012 - 09:09 AM
If I have to take a stab at it. I'd say its the rednet.send (Hostname,…) in drawScene()

That's defined out in the script's scope as local and you're trying to access it in a function. I don't believe that carries across that scope like one might expect.

Now its 2am here and I've been using lua for a grand total of like 5 days… but I'd say that's your problem and you might consider passing hostname up the stack as a parameter.

Just my 2cents. :(/>/>