|
| 30 Oct 2016 08:33 AM |
script: local hash = {["one"] = {1,"P1"}, ["two"] = {2,"P2"}}
for some reason, calling hash[1] and hash[2] are nil, however, in the pairs loop, the indices are "one" and "two", and the values are table: 1F059AC8 and table: 1F059588. Why is hash[1] and hash[2] nil?
r+ |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:37 AM |
| ############################################################################################################################################################################################################################################################################################################################ |
|
|
| Report Abuse |
|
|
Praelance
|
  |
| Joined: 18 Oct 2016 |
| Total Posts: 607 |
|
|
| 30 Oct 2016 08:37 AM |
the array and dictionary parts of a table are different
"one" is the key, not [1], [1] is nil
you use a generic for loop as you've found when you need to access the dictionary portion
|
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:39 AM |
http:// pastebin. com/ 2sdq2QJz |
|
|
| Report Abuse |
|
|
Praelance
|
  |
| Joined: 18 Oct 2016 |
| Total Posts: 607 |
|
|
| 30 Oct 2016 08:40 AM |
"where keys are stored as STRINGS"
not limited to that
can be userdata
|
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:42 AM |
??? Lol are you serious
You cant store userdatum as a key In lua you can only have string and number keys to tables and userdatum You can store userdata AT THAT KEY, but not AS THE KEY |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:43 AM |
An example is getChildren which returns an array of objects:
{ Workspace, Baseplate, Terrain }
Or also indexing
print(game.Workspace) print(game["Workspace"]) |
|
|
| Report Abuse |
|
|
Praelance
|
  |
| Joined: 18 Oct 2016 |
| Total Posts: 607 |
|
|
| 30 Oct 2016 08:44 AM |
local part = workspace.Part local tab = {} tab[part] = "test" print(tab.part)
yes i am serious
|
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:47 AM |
Still wrong
local t = {} t[game] = "hi" print(t.game) --nil |
|
|
| Report Abuse |
|
|
|
| 30 Oct 2016 08:48 AM |
o wait kek
local t = {} t[game] = "hi" print(t[game]) you did it wrong |
|
|
| Report Abuse |
|
|
Praelance
|
  |
| Joined: 18 Oct 2016 |
| Total Posts: 607 |
|
|
| 30 Oct 2016 08:49 AM |
> local tesst = Instance.new("Part") local tab = {} tab[tesst] = "3" for key, value in pairs(tab) do print(key.Position) end 0, 0, 0
|
|
|
| Report Abuse |
|
|
Praelance
|
  |
| Joined: 18 Oct 2016 |
| Total Posts: 607 |
|
|
| 30 Oct 2016 08:53 AM |
my point was that tab.part was going to be nil
i am right
|
|
|
| Report Abuse |
|
|