Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you access a dictionary?

Asked by
NRCme 0
8 years ago

I have a dictionary:

local Skills = {
    ["IP"] = 1,
    ["virus"] = 1,
    ["firewall"] = 1,
    ["trace"] = 1,
    ["network"] = 1,
    ["remote"] = 1,
    ["physical"] = 1,
    ["stealth"] = 1,
    ["local"] = 1,
    ["cracker"] = 1,
    ["level"] = 1
}   

but how do I access it?

0
Access in what way? What information do you want to store / retrieve? BlueTaslem 18071 — 8y
0
Well I want to be able to access it by string/name and be able to change the values NRCme 0 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

If you're talking about accessing the information inside the dictionary, then you just index the table using a dot . or square brackets [ ]. I'm not gonna go into crazy detail about it, so I'll just leave you with these examples, as they're pretty easy to pick up:

local Skills = {
    ["IP"] = 1,
    ["virus"] = 1,
    ["firewall"] = 1,
    ["trace"] = 1,
    ["network"] = 1,
    ["remote"] = 1,
    ["physical"] = 1,
    ["stealth"] = 1,
    ["local"] = 1,
    ["cracker"] = 1,
    ["level"] = 1
}   

print(Skills["IP"]) -- Prints the value Skills.IP represents 
print(Skills.IP) -- this works too (because the key follows the same rules variables obide by)

Skills.IP = 5 -- To change the key, simply set it a new value.

If you're confused about any of this, let me know. Sorry this couldn't be one of my long answers, I just didn't have the time.

Ad

Answer this question