Page 1 of 1

Why this gets an error?

Posted: Mon Jan 23, 2017 3:04 pm
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?

Re: Why this gets an error?

Posted: Mon Jan 23, 2017 3:13 pm
by Klonan
game.evolution_factor doesn't exists whe defining things at the data stage

Re: Why this gets an error?

Posted: Mon Jan 23, 2017 3:17 pm
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

Re: Why this gets an error?

Posted: Mon Jan 23, 2017 3:51 pm
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.

Re: Why this gets an error?

Posted: Mon Jan 23, 2017 4:23 pm
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?

Re: Why this gets an error?

Posted: Mon Jan 23, 2017 4:43 pm
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.

Re: Why this gets an error?

Posted: Tue Jan 24, 2017 8:57 am
by /odosk/
Then there is no way to do what I thought?

Re: Why this gets an error?

Posted: Tue Jan 24, 2017 9:23 am
by Adil
What actually did you "thought"?

Re: Why this gets an error?

Posted: Tue Jan 24, 2017 11:15 am
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.

Re: Why this gets an error?

Posted: Tue Jan 24, 2017 11:50 am
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.