Ask for a Lua syntax

Place to get help with not working mods / modding interface.
Post Reply
sdgmlj
Fast Inserter
Fast Inserter
Posts: 123
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Ask for a Lua syntax

Post 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?

Xorimuth
Filter Inserter
Filter Inserter
Posts: 430
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Ask for a Lua syntax

Post by Xorimuth »

a[1]["b"] or a[1].b both work.

sdgmlj
Fast Inserter
Fast Inserter
Posts: 123
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: Ask for a Lua syntax

Post 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?

Pi-C
Smart Inserter
Smart Inserter
Posts: 1274
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Ask for a Lua syntax

Post 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
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

sdgmlj
Fast Inserter
Fast Inserter
Posts: 123
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: Ask for a Lua syntax

Post 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. :D :D :D

Post Reply

Return to “Modding help”