Why this gets an error?

Place to get help with not working mods / modding interface.
/odosk/
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Oct 04, 2016 2:25 pm
Contact:

Why this gets an error?

Post by /odosk/ »

very simple code

Code: Select all

data.raw["unit-spawner"]["biter-spawner"].max_health = 1000 + (game.evolution_factor * 2000)
data.raw["unit-spawner"]["spitter-spawner"].max_health = 1000 + (game.evolution_factor * 2000)

data.raw.unit["small-biter"].max_health = data.raw.unit["small-biter"].max_health * (1 + game.evolution_factor)
data.raw.unit["medium-biter"].max_health = data.raw.unit["medium-biter"].max_health * (1 + (0.5 * game.evolution_factor))
data.raw.unit["small-spitter"].max_health = data.raw.unit["small-spitter"].max_health * (1 + game.evolution_factor)
data.raw.unit["medium-spitter"].max_health = data.raw.unit["medium-spitter"].max_health * (1 + (0.5 * game.evolution_factor))

data.raw.unit["small-biter"].movement_speed = data.raw.unit["small-biter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["medium-biter"].movement_speed = data.raw.unit["medium-biter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["big-biter"].movement_speed = data.raw.unit["big-biter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["behemoth-biter"].movement_speed = data.raw.unit["behemoth-biter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["small-spitter"].movement_speed = data.raw.unit["small-spitter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["medium-spitter"].movement_speed = data.raw.unit["medium-spitter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["big-spitter"].movement_speed = data.raw.unit["big-spitter"].movement_speed * (1 + (0.5 * game.evolution_factor))
data.raw.unit["behemoth-spitter"].movement_speed = data.raw.unit["behemoth-spitter"].movement_speed * (1 + (0.5 * game.evolution_factor))
and... it displays error(nil value)
how can I solve it?
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Why this gets an error?

Post by Klonan »

game.evolution_factor doesn't exists whe defining things at the data stage
/odosk/
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Oct 04, 2016 2:25 pm
Contact:

Re: Why this gets an error?

Post by /odosk/ »

Klonan wrote:game.evolution_factor doesn't exists whe defining things at the data stage
Yes thats what I thought but
when I added
game.evolution_factor = 0, still does not work
Rseding91
Factorio Staff
Factorio Staff
Posts: 16000
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Why this gets an error?

Post by Rseding91 »

/odosk/ wrote:
Klonan wrote:game.evolution_factor doesn't exists whe defining things at the data stage
Yes thats what I thought but
when I added
game.evolution_factor = 0, still does not work
"game" doesn't exist during setting up prototypes - the main menu isn't even loaded yet let alone a map loaded.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Why this gets an error?

Post by Adil »

Did you add it as

Code: Select all

game={evolution_factor=0}
?

Also, it tells you more than just "error(nil value)", why are you telling us less?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Why this gets an error?

Post by daniel34 »

Adil wrote:Did you add it as

Code: Select all

game={evolution_factor=0}
?
Even then what he's trying to do won't work. The purpose of the code is to change the max health and movement speed of enemies at runtime depending on the evolution factor, which is not possible in Factorio. Values in data.raw are only loaded when loading Factorio, you can't change them later during a game.
quick links: log file | graphical issues | wiki
/odosk/
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue Oct 04, 2016 2:25 pm
Contact:

Re: Why this gets an error?

Post by /odosk/ »

Then there is no way to do what I thought?
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Why this gets an error?

Post by Adil »

What actually did you "thought"?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Why this gets an error?

Post by bobingabout »

It looks like he's trying to change the max health of a biter based on the evolution factor. This is a thing that is currently not possible to do.

There was recently a similar question about increasing the max health of a turret based on kill count, the answer there was the same.

Max health can only be modified during data phase. Evolution factor is a game variable (as is kill count), therefore, one cannot be used to modify the other.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Why this gets an error?

Post by darkfrei »

bobingabout wrote:It looks like he's trying to change the max health of a biter based on the evolution factor. This is a thing that is currently not possible to do.

There was recently a similar question about increasing the max health of a turret based on kill count, the answer there was the same.

Max health can only be modified during data phase. Evolution factor is a game variable (as is kill count), therefore, one cannot be used to modify the other.
But mobs (and turrets) can have some slots for special items, like beacons with modules. It didn't change the entities, but some properties. Not now, but in 0.15 or later.

If it's stuckable, you can add this items every experience and mobs can be changed with it.
Post Reply

Return to “Modding help”