Go to the page 2 for the current question please
————————————————- !!! ———————————————————-
First excuse me If I do mistakes in the language, it's not my first one.
Well, I'm making a program who's talking with an other computer to work, and the requireds informations are stocked in a table.
When I try to display one of the informations in one of these tables, it return me the following error :
"Test:113: attempt to index ? (a nil value)"
Concretly I know it mean the value is null, but I don't understand why :s
Here is the code of the client computer:
---Ask the server---
rednet.open("top")
serverID = 14
rednet.send(serverID,"opcode1")
local event, senderID, message, distance = os.pullEvent()
if event == "rednet_message" then
users = textutils.unserialize(message)
end
sleep(0.1)
rednet.send(serverID,"opcode2")
local event, senderID, message, distance = os.pullEvent()
if event == "rednet_messag" then
moneys = textutils.unserialize(message)
end
sleep(0.1)
rednet.send(serverID,"opcode3")
local event, senderID, message, distance = os.pullEvent()
if event == "rednet_message" then
lockeds = textutils.unserialize(message)
end
sleep(0.1)
rednet.send(serverID,"opcode4")
local event, senderID, message, distance = os.pullEvent()
if event == "rednet_message" then
codes = textutils.unserialize(message)
end
sleep(0.1)
rednet.send(serverID,"opcode5")
local event, senderID, message, distance = os.pullEvent()
if event == "rednet_message" then
isInactive = textutils.unserialize(message)
end
--Define functions--
function getData()
if actualUser == "Arektor" then
user = users[1]
money = moneys[1]
code = codes[1]
isLocked = lockeds[1]
elseif actualUser == "Leo" then
user = users[2]
money = moneys[2]
code = codes[2]
isLocked = lockeds[2]
elseif actualUser == "Maxime" then
user = users[3]
money = moneys[3]
code = codes[3]
isLocked = lockeds[3]
elseif actualUser == "Crosf" then
user = users[4]
money = moneys[4]
code = codes[4]
isLocked = lockeds[4]
elseif actualUser == "Magni" then
user = users[5]
money = moneys[5]
code = codes[5]
isLocked = lockeds[5]
end
end
--------------------
function displayData()
term.setCursorPos(1,1)
term.setBackgroundColor(8)
write("User: "..user)
term.setCursorPos(30,1)
print("Money: "..money)
term.setCursorPos(1,2)
print("Code: "..code)
term.setCursorPos(30,2)
print("Locked: "..isLocked)
end
--------------------
function displayPanel()
loadImage("Menu")
getData() -- getData = Obtain informations about the user's account
displayData() -- displayData = Display these informations
term.setCursorPos(51,1)
term.setBackgroundColor(16384)
write("X")
term.setCursorPos(8,16)
term.setBackgroundColor(512)
write("Get")
term.setCursorPos(8,17)
write("Money")
term.setCursorPos(21,16)
write("Stock")
term.setCursorPos(21,17)
write("Money")
term.setCursorPos(40,18)
write("Lock Account")
term.setCursorPos(27,4)
write("Send Money")
term.setCursorPos(27,5)
write("to an other")
term.setCursorPos(27,6)
write("account.")
end
--------------------
function loadImage(name)
image = paintutils.loadImage("/Data/Images/"..name)
paintutils.drawImage(image,1,1)
end
--------------------
--Authentification--
loadImage("Intro")
term.setCursorPos(4,13)
term.setBackgroundColor(8)
write("Username")
write(users[1])
term.setCursorPos(2,16)
write("Password Code")
term.setCursorPos(19,11)
term.setTextColor(8192)
write("Remote Access Edition")
h = 0
while h == 0 do
term.setTextColor(1)
term.setCursorPos(3,14)
term.setBackgroundColor(256)
user = read()
term.setCursorPos(3,17)
code = read("*")
if user == users[1] and code == codes[1] then
actualUser = "Arektor"
h = 1
elseif user == users[2] and code == codes[2] then
actualUser = "Leo"
h = 1
elseif user == users[3] and code == codes[3] then
actualUser = "Maxime"
h = 1
elseif user == users[4] and code == codes[4] then
actualUser = "Crosf"
h = 1
elseif user == users[5] and code == codes[5] then
actualUser = "Magni"
h = 1
else
loadImage("Intro")
term.setCursorPos(4,13)
term.setBackgroundColor(8)
write("Username")
term.setCursorPos(2,16)
write("Password Code")
term.setCursorPos(19,11)
term.setTextColor(8192)
write("Remote Access Edition")
term.setCursorPos(38,4)
term.setBackgroundColor(256)
term.setTextColor(16384)
print("Invalid")
term.setCursorPos(38,5)
print("combinaison of")
term.setCursorPos(38,6)
print("username and")
term.setCursorPos(38,7)
print("password code.")
end
end
--Bank Account Control--
displayPanel()
v = 0
while v == 0 do
local event, button, x, y = os.pullEvent("mouse_click")
if x >= 4 and y >= 16 and x <= 6 and y <= 17 then
getMoney()
v = 1
elseif x >= 17 and x <= 19 and y <= 17 and y >= 16 then
stockMoney()
v = 1
elseif x >= 44 and y >= 15 and x <= 48 and y <= 17 then
lockAcount()
v = 1
elseif x == 51 and y == 1 then
os.shutdown()
end
end
And here is the server computer code:
rednet.open("top")
term.clear()
term.setCursorPos(1,1)
term.setTextColor(32)
print("A'Bank Server Platform System")
print(" ")
term.setTextColor(1)
local users = {
"Arektor";
"Léo";
"Maxime";
"Crosf";
"Magni";
}
--------------------
local moneys = {
0;
0;
0;
0;
0;
}
--------------------
local lockeds = {
"false";
"false";
"false";
"false";
"false";
}
--------------------
local codes = {
"4921s-ender";
"7436p-zlqng";
"941rt-nrj95";
"41237-eaq7m";
"uig25-etn25";
}
--------------------
local isInactive = {
"false";
"false";
"false";
"false";
"false";
}
--------------------
local falseOpcode = {
"uiglenf571ev5";
"arzeioh546vx312";
"endptzearek2684";
"rezabjn7-4z2f";
"rzeijor-4245n-z41f";
}
--Prepare opcodes packets for transmission--
userss = textutils.serialize(users)
moneyss = textutils.serialize(moneys)
lockedss = textutils.serialize(lockeds)
codess = textutils.serialize(codes)
isInactives = textutils.serialize(isInactive)
falseOpcodes = textutils.serialize(falseOpcode)
--Start the platform system--
i = 50
while i == 50 do
local event, senderID, message, distance = os.pullEventRaw()
if event == "rednet_message" then
if message == "opcode1" then
sleep(0.1)
rednet.send(senderID,userss)
print("Opcode 1 (Users) was sent to the router "..senderID)
elseif message == "opcode2" then
sleep(0.1)
rednet.send(senderID,moneyss)
print("Opcode 2 (Moneys) was sent to the router "..senderID)
elseif message == "opcode3" then
sleep(0.1)
rednet.send(senderID,lockedss)
print("Opcode 3 (Lockeds) was sent to the router "..senderID)
elseif message == "opcode4" then
sleep(0.1)
rednet.send(senderID,codess)
print("Opcode 4 (Password Codes) was sent to the router "..senderID)
elseif message == "opcode5" then
sleep(0.1)
rednet.send(senderID,isInactives)
print("Opcode 5 (Is Inactive ?) was sent to the router "..senderID)
else -- Detect if a false message is sended for trying to receive an opcode.
print("Router "..senderID.." tried to send a wrong message!")
rednet.send(senderID,falseOpcodes)
end
elseif event == "terminate" then
print("Bank Server Platform ended! A'Bank is now disabled!!")
i = 51
end
end
Maybe the error is obvious… But I can't find it T_T