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

This doesn't wok on startup, but it work..

Started by Asdramelesh, 28 February 2014 - 10:06 AM
Asdramelesh #1
Posted 28 February 2014 - 11:06 AM
Hi everyone, I need help because I really don't understand what is happening :

I'm writing a program with a list of players on the server, so I use table.
This program is called startup, when I launch it typing "startup" on a computer it work (return Asdramelesh 0), but if I reboot the computer he say that I attempt to index nil.

Can you help me please?

startup :

players = {asdra,yakoo,lous,leios,unike,minefuch,zeykoz,lazik,spekinoz,boson,lucky}
asdra = {["name"]="asdramelesh",["presence"]=0}
yakoo = {["name"]="yakoo29",["presence"]=0}
a = players[1]["name"]
b = players[1]["presence"]
print(a.." " .. B)/>
Edited on 28 February 2014 - 10:08 AM
nolongerexistant #2
Posted 28 February 2014 - 11:56 AM
This is because when the Computer boots, it doesn't know what any of the variables in the players table are, you'll have to define them before you try to use them in the table. The reason it does know what they are when you manually run the program is because you're setting global variables, you should use local variables unless you need them externally.


local asdra = {["name"]="asdramelesh",["presence"]=0}
local yakoo = {["name"]="yakoo29",["presence"]=0}

local players = {asdra,yakoo} -- The others are still undefined

local a = players[1]["name"]
local b = players[1]["presence"]

print(a.." " .. B)/>/>
Edited on 28 February 2014 - 10:56 AM
Asdramelesh #3
Posted 28 February 2014 - 12:03 PM
Okay I understand now, thanks a lot!