Syntax error

Place to get help with not working mods / modding interface.
Post Reply
Hyalskavran
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Nov 22, 2019 9:27 pm
Contact:

Syntax error

Post by Hyalskavran »

Hello !

I'm trying to make a small mod, but it even it's current state it gives me an error.

Code: Select all

script.on_event(defines.events.on_console_chat, function(event)
message = new_message
if new_message == "baza" then
data.raw.unit-spawner["biter-spawner"].health = 0
data.raw.unit-spawner["spitter-spawner"].health = 0
end
end
)
Factorio tells me there is syntax error on line 4 near "-" but I can't figure it out since I copied the names from the wiki.

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

Re: Syntax error

Post by Pi-C »

Hyalskavran wrote:
Fri Nov 22, 2019 9:38 pm
Hello !

I'm trying to make a small mod, but it even it's current state it gives me an error.

Code: Select all

script.on_event(defines.events.on_console_chat, function(event)
message = new_message
if new_message == "baza" then
data.raw.unit-spawner["biter-spawner"].health = 0
data.raw.unit-spawner["spitter-spawner"].health = 0
end
end
)
Factorio tells me there is syntax error on line 4 near "-" but I can't figure it out since I copied the names from the wiki.
Several things wrong with it:
  • It should be

    Code: Select all

    data.raw["unit-spawner"]["biter-spawner"].health = 0
    
    Otherwise, it's the substraction of data.raw.unit and spawner["biter-spawner"].health.
  • Even then, it wouldn't work because the table data isn't available in the control stage (where events are handled), but only in the data stage (where prototypes are defined).
  • Where does new_message on line 2 come from? Do you mean this, perhaps?

    Code: Select all

    local new_message = event.message
    
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: Syntax error

Post by Pi-C »

Does this do what you want?

Code: Select all

script.on_event(defines.events.on_console_chat, function(event)
    local new_message = event.message
    if new_message == "baza" then
        local spawners = game.surfaces["nauvis"].find_entities_filtered{type="unit-spawner"}
	for _, spawner in pairs(spawners) do 
	    spawner.destroy() 
	end
    end
end)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Hyalskavran
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Nov 22, 2019 9:27 pm
Contact:

Re: Syntax error

Post by Hyalskavran »

Yes, and yes. Thank you guys so much for such a quick help and an explanation. I will try to learn more about what I'm trying to do next time before doing it.

Post Reply

Return to “Modding help”