Forums WoW Modding Support Archives Azerothcore Discord Archives [DiscordArchive] Without declaration ?

[DiscordArchive] Without declaration ?

[DiscordArchive] Without declaration ?

rektbyfaith
Administrator
0
02-02-2024, 09:14 PM
#1
Archived author: iThorgrim • Posted: 2024-02-02T21:14:37.276000+00:00
Original source

Without declaration ?
rektbyfaith
02-02-2024, 09:14 PM #1

Archived author: iThorgrim • Posted: 2024-02-02T21:14:37.276000+00:00
Original source

Without declaration ?

rektbyfaith
Administrator
0
02-02-2024, 09:18 PM
#2
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
```
rektbyfaith
02-02-2024, 09:18 PM #2

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
```

rektbyfaith
Administrator
0
02-02-2024, 09:21 PM
#3
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.
rektbyfaith
02-02-2024, 09:21 PM #3

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.

rektbyfaith
Administrator
0
02-02-2024, 09:21 PM
#4
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
rektbyfaith
02-02-2024, 09:21 PM #4

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

rektbyfaith
Administrator
0
02-02-2024, 09:23 PM
#5
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
```
rektbyfaith
02-02-2024, 09:23 PM #5

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
```

Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)