Posted 03 January 2016 - 04:49 PM
I am having a problem with my program….
Whenever I try to access an index on it it just returns (ERROR: Index expected, got string)
I'll give a snippet of the code and if I need to post more of it tell me and I will add it.
Whitelist[50] = P
where P is the player to be added and Whitelist is the list of allowed players.
I've tried EVERY single value, it just will not work! :(/>
EDIT: Here's my code:
Thanks for the help.
Now time to add the final thing, and if that works, you won't hear from me again on this post.
Now I'm having a problem with my Wifi Controller (see below's spoiler). It says on line 5 that it's attempting to call nil.
EDIT2: I'm dumb. Fixed the errors and am waiting for thread to close.
Whenever I try to access an index on it it just returns (ERROR: Index expected, got string)
I'll give a snippet of the code and if I need to post more of it tell me and I will add it.
Whitelist[50] = P
where P is the player to be added and Whitelist is the list of allowed players.
I've tried EVERY single value, it just will not work! :(/>
EDIT: Here's my code:
Spoiler
local P = peripheral.find("modem")
if P == nil then
error("There is no router on this PC!")
end
print("Got the modem!")
P.open(15)
Whitelist = {"Famous5000"}
if fs.exists("Whitelist") then
Whitelist = io.open("Whitelist","r")
Whitelist = Whitelist:read()
local W = {}
for I = 1,#Whitelist do
W = Whitelist[I] -- I screwed up here, should have been W[I] = Whitelist[I] <FIXED>
end
Whitelist = W
end
while true do
local _,_,Channel,_,Message = os.pullEvent("modem_message")
if type(Message) == "table" then
sleep(0.1)
local Plr = Message[1]
INVALID = false
if Plr ~= "Famous5000" then
INVALID = true
for I = 1,#Whitelist do
if Plr == Whitelist[I] then
INVALID = false
end
end
if INVALID == true then
term.setTextColor(colors.red)
print("A blocked attempt to access this system from "..Plr)
term.setTextColor(colors.white)
end
end
local Msg = Message[2]
if INVALID == false then
if Msg:lower() == "open" then
redstone.setAnalogOutput("top",15)
sleep(2)
redstone.setAnalogOutput("top",0)
end
if Msg:lower() == "shutdown" then
break
end
if Msg:lower():sub(0,3) == "add" then
local P = Msg:sub(5)
local C = 0
for I = 1,#Whitelist do
C = I + 1
end
C = tonumber(C)
Whitelist[1] = P --Problem resides here, prints error
end
if Msg:lower():sub(0,3) == "rem" then
local P = Msg:sub(5)
if P == "clr" then
Whitelist = {"Famous5000"}
else
for I = 1,#Whitelist do
if Whitelist[I]:lower():match(P:lower()) then
table.remove(Whitelist,I)
end
end
end
end
print("Recieved message from "..Plr)
end
end
end
local W = fs.open("Whitelist","w")
print("I have been told to shut down. Rebooting...")
sleep(3)
if W then
for n,T in ipairs(Whitelist) do
W.write(T.."\n")
end
W.close()
else
print("Access denied. Please fix this")
end
sleep(10)
if not fs.exists("startup") then
local R = fs.open("startup","w")
Lines = {"shell.run(\"Detector\")",
"os.reboot()"}
if R then
for n,T in ipairs(Lines) do
R.write(T.."\n")
end
end
R.close()
os.reboot()
end
Oops! I see an obvious problem. Going to try to solve it via the computercraft thing and if that doesn't work, I'll report back to you.I completely spaced out about adding the . It works fine now.That error message means Whitelist is a string. I don't know how or why until you post the code, but it is.
Now time to add the final thing, and if that works, you won't hear from me again on this post.
Spoiler
PS, it's my first time using this thread, so now I know to paste the whole code next time. Thanks for the help!Spoiler
print("Please input username.")
local U = io.input() --It's supposed to wait until someone inputs something here, but that's not happening, so I'm confused
local M = peripheral.find("modem")
M.open(15)
M.broadcast(15,15,{U,"TEST"})
local _,_,_,_,Msg = os.pullEvent("modem_message")
if Msg == "Test Successful!" then
term.setTextColor(colors.green)
print("Successfully validated!")
term.setTextColor(colors.white)
end
while true do
term.clear()
print("Input the command.")
local C = io.input()
M.broadcast(15,15,{U,C})
end
Edited on 03 January 2016 - 11:17 PM