[DiscordArchive] Without declaration ?
[DiscordArchive] Without declaration ?
Archived author: iThorgrim • Posted: 2024-02-02T21:14:37.276000+00:00
Original source
Without declaration ?
Archived author: iThorgrim • Posted: 2024-02-02T21:18:15.873000+00:00
Original source
In Lua, you can't directly assign values to nested arrays without first declaring them. You must first create the appropriate array structure by declaring each level.
Exemple :
```lua
-- Declaration of the main array
local myArray = {}
-- Declaration of the first level
myArray["level1"] = {}
-- Assigning values to the second level
myArray["level1"]["value1"] = 10
myArray["level1"]["value2"] = "Hello"
-- Displaying the resulting array
print(myArray["level1"]["value1"]) -- Will print 10
print(myArray["level1"]["value2"]) -- Will print Hello
-- Exemple 2
local myArray = {
["level1"] = {
["value1"] = 10,
["value2"] = "Hello"
}
}
print(myArray["level1"]["value1"]) -- Will print 10
print(myArray["level1"]["value2"]) -- Will print Hello
```
Archived author: Honey • Posted: 2024-02-02T21:21:06.229000+00:00
Original source
That's exactly what I was saying. There's no declaration of the second level in the array hence why I suspect the script fails.
Archived author: iThorgrim • Posted: 2024-02-02T21:21:37.040000+00:00
Original source
Yes but u don't have to declare the second level outside the first level like Exemple 2
Archived author: iThorgrim • Posted: 2024-02-02T21:23:24.623000+00:00
Original source
U can do this :
```lua
local myArray = {
Level_1 = {
Level_2 = {
Level_3 = {
["value_1"] = 10
}
}
}
}
print(myArray.Level_1.Level_2.Level_3["value_1"]) -- Will print 10
```