Page 1 of 1
Ask for a Lua syntax
Posted: Fri Apr 29, 2022 2:12 pm
by sdgmlj
There are two layers of braces in a table. How can I get its value?
For example:
a = {
{
b = 5
},
}
a.b = 5 ?? That's wrong,How can I express it?
Re: Ask for a Lua syntax
Posted: Fri Apr 29, 2022 2:20 pm
by Xorimuth
a[1]["b"] or a[1].b both work.
Re: Ask for a Lua syntax
Posted: Fri Apr 29, 2022 2:50 pm
by sdgmlj
Xorimuth wrote: ↑Fri Apr 29, 2022 2:20 pm
a[1]["b"] or a[1].b both work.
Thank you, but it still reported an error
attempt to index field'?'(a nil value)
The content of the original script is as follows:
action = {
{
type = "direct",
action_delivery = {
{
type = "projectile",
projectile = "anti-material-rifle-ammo-3",
starting_speed = 3,
direction_deviation = 0.02,
range_deviation = 0.02,
max_range = 50,
source_effects = {
{
type = "create-explosion",
entity_name = "explosion-gunshot",
},
},
},
},
force = "not-same",
},
},
I want to get the value of "max_range". How can I express it?
Re: Ask for a Lua syntax
Posted: Fri Apr 29, 2022 3:01 pm
by Pi-C
sdgmlj wrote: ↑Fri Apr 29, 2022 2:50 pm
action = {
{
type = "direct",
action_delivery = {
{
type = "projectile",
projectile = "anti-material-rifle-ammo-3",
starting_speed = 3,
direction_deviation = 0.02,
range_deviation = 0.02,
max_range = 50,
source_effects = {
{
type = "create-explosion",
entity_name = "explosion-gunshot",
},
},
},
},
force = "not-same",
},
},
Please, use code markup! This way, it's much easier to read because indention will not be removed:
Code: Select all
action = {
{
type = "direct",
action_delivery = {
{
type = "projectile",
projectile = "anti-material-rifle-ammo-3",
starting_speed = 3,
direction_deviation = 0.02,
range_deviation = 0.02,
max_range = 50,
source_effects = {
{
type = "create-explosion",
entity_name = "explosion-gunshot",
},
},
},
},
force = "not-same",
},
},
I want to get the value of "max_range". How can I express it?
That would be
Code: Select all
action[1].action_delivery[1].max_range
Re: Ask for a Lua syntax
Posted: Fri Apr 29, 2022 3:14 pm
by sdgmlj
Pi-C wrote: ↑Fri Apr 29, 2022 3:01 pm
sdgmlj wrote: ↑Fri Apr 29, 2022 2:50 pm
action = {
{
type = "direct",
action_delivery = {
{
type = "projectile",
projectile = "anti-material-rifle-ammo-3",
starting_speed = 3,
direction_deviation = 0.02,
range_deviation = 0.02,
max_range = 50,
source_effects = {
{
type = "create-explosion",
entity_name = "explosion-gunshot",
},
},
},
},
force = "not-same",
},
},
Please, use code markup! This way, it's much easier to read because indention will not be removed:
Code: Select all
action = {
{
type = "direct",
action_delivery = {
{
type = "projectile",
projectile = "anti-material-rifle-ammo-3",
starting_speed = 3,
direction_deviation = 0.02,
range_deviation = 0.02,
max_range = 50,
source_effects = {
{
type = "create-explosion",
entity_name = "explosion-gunshot",
},
},
},
},
force = "not-same",
},
},
I want to get the value of "max_range". How can I express it?
That would be
Code: Select all
action[1].action_delivery[1].max_range
Thank you. I see. The back one is also two floors.