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

[Question][Problem]Server / Client Login ...

Started by menof36go, 22 November 2012 - 02:56 AM
menof36go #1
Posted 22 November 2012 - 03:56 AM
Hi :(/>/>

Error : startup:32: bad argument: table expected, got number
Code : The most Code is from your Wiki because i am new in Lua .

print("Attention ! This is a Server no User Pc !") -- this is from the computercraft wiki :(/>/>/>
sleep(3)
print("				")
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
local firstCycle = true
local validSender = false
local modemSide = "left"
local valid = false
users = {"menof36go", "user2", "user3", "user4", "user5", "user6", "user7", "user8", "user9" }
passwords = {"0815", "password2", "password3", "password4", "password5", "password6", "password7", "password8", "password9" }
senders = { 1, 2, 3, 4 }
function bootUp()
rednet.open("back")
rednet.open("left")
rednet.open("right")
end
while true do
validSender = false
if firstCycle then
  bootUp()
  firstCycle = false
end
senderId, message, distance = rednet.receive()
for i,v in ipairs(senders) do
  if v == senderId then -- it said startup:32: bad argument: table expected, got number...
   validSender = true
   break
  end
end
if validSender then
  for i,v in ipairs(users) do
   if message == v then
	valid = true
	password = passwords[i] -- why theres a [i] ?
	break
   else
	valid = false
   end
  end
  if valid then
   rednet.send(senderId, password, true)
  else
   rednet.send(senderId, "Not Valid", true)
  end
end
end

Another Question is there away that a user can register on server from an other computer ?
I hope you can help my ,
thanks Fabi =) !
menof36go #2
Posted 22 November 2012 - 05:21 AM
Fixed …
i forgot the [] at passwords
remiX #3
Posted 22 November 2012 - 08:35 AM
By the way, with the senders table you have, you actually do not have to do for i, v in pars(senders) you can do:


for i = 1, #senders do
  if senderId == senders[i] then
   validSender = true
   break
  end
end