I am trying to add a number from a dictionary, but how do I get an individual number indexed?
Indexing:
1 | Player.Character:WaitForChild( 'RunningSpeed' ).Value = 25 + (KillerStats [ 1 ] ) |
Dictionary
1 | local KillerStats = { |
2 | Speed = 1 , |
3 | Damage = 3 , |
4 | Vision = 10 |
5 | } |
You don't index dictionary's with integers (whole numbers) instead you index them with the name you gave the index to be.
Example:
1 | local diction = { |
2 | [ "Index" ] = "Some Value" ; |
3 | [ "Something" ] = "Another value" |
4 | } |
5 |
6 | for i, v in pairs (diction) do |
7 | print (i..v) -- outputs "Index" and "Something" along with their values |
8 | end |
So you know the semi colon is the same as using a comma
Lets go back to the example you had. Your index is different then mine but here's how you index what you want from your dictionary.
01 | local KillerStats = { |
02 | -- I put brackets on your index |
03 |
04 | [ "Speed" ] = 1 , |
05 | [ "Damage" ] = 3 , |
06 | [ "Vision" ] = 10 |
07 | } |
08 |
09 | print (KillerStats.Speed) -- or |
10 | print (KillerStats [ "Speed" ] ) |
11 | -- Should output 1 (*2) |
Hope this helps!
I haven't done much with dictionaries yet but to my understanding it's just like looking up the word in a dictionary. You don't search it by list because it's not in a numbered list. You would search it by name and then get the definition (Value).
1 | Player.Character:WaitForChild( 'RunningSpeed' ).Value = 25 + (KillerStats [ Damage ] ) |
The problem is that what you assigned isn't doesn't become the original index anymore; using a dictionary you need to specify your custom index for roblox to examine and verify it. For example,
1 | --Dictionary |
2 | local KillerStats = { |
3 | [ "Speed" ] = 1 , |
4 | [ "Damage" ] = 3 , |
5 | [ "Vision" ] = 10 |
6 | } |
1 | --Script |
2 | Player.Character:WaitForChild( 'RunningSpeed' ).Value = 25 + (KillerStats [ "Speed" ] ) |