Make machine only work during day time

Place to get help with not working mods / modding interface.
Post Reply
CryptoCat
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 06, 2021 1:52 am
Contact:

Make machine only work during day time

Post by CryptoCat »

I want to make machine that only works during the day, similar to solar panel. I tried using a function that would output me a crafting speed of 0 during the night hours, making the machine stop during night. However I get error:
"Value (function) can't be saved at property tree ROOT.assembling-machine.test-entity.crafting_speed"

Is there another way to achieve this?
I want the machine to work passively but only during the day, as if it was "solar powered" but without having to add additional solar panels or power generation

meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Make machine only work during day time

Post by meifray »

no worries,you can just set it to very small value,it just not accept 0.
Last edited by meifray on Sat Nov 06, 2021 9:38 am, edited 1 time in total.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 314
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Make machine only work during day time

Post by Stringweasel »

Crafting speed is not setable in the control stage. You can see it's only readable "[R]" in the docs:
https://lua-api.factorio.com/latest/Lua ... ting_speed

You will have to achieve that mechanic some other way. For example having two entities, where one has a crafting speed of zero. When night comes you swop out the working one with the non-working on through scripting. You'll have to manually take care of the recipe, crafting progress, modules, upgrade order, and things like that.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

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

Re: Make machine only work during day time

Post by Pi-C »

Stringweasel wrote:
Sat Nov 06, 2021 9:27 am
Crafting speed is not setable in the control stage. You can see it's only readable "[R]" in the docs:
https://lua-api.factorio.com/latest/Lua ... ting_speed

You will have to achieve that mechanic some other way. For example having two entities, where one has a crafting speed of zero. When night comes you swop out the working one with the non-working on through scripting.
Why swap entities? Wouldn't it be enough to toggle LuaEntity.active?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 314
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Make machine only work during day time

Post by Stringweasel »

Pi-C wrote:
Sat Nov 06, 2021 9:39 am
Why swap entities? Wouldn't it be enough to toggle LuaEntity.active?
Why now that would be a much simpler solution! Next time I'll finish my cup of coffee first.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

CryptoCat
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 06, 2021 1:52 am
Contact:

Re: Make machine only work during day time

Post by CryptoCat »

I have this code currently:

Code: Select all

if hours < 4 or hours > 22 then
	entity.active = false
end
if hours >= 4 or hours <= 22 then
	entity.active = true
end
where I have a local variable entity and I give it the path to my entity lua file, however the machine does not stop working. I tried the code in, and outside of a loop, both of them don't work. I also tried

Code: Select all

set_frozen(entity[, mode=true]
however Factorio doesn't like the comma and gives me error that it was expecting something near comma.
To get the time, I am using similar code to StatsGUI because I know that works and I haven't found documentation on the game time, maybe I was searching in wrong place.

meifray
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat May 29, 2021 6:12 pm
Contact:

Re: Make machine only work during day time

Post by meifray »

CryptoCat wrote:
Sat Nov 06, 2021 7:06 pm
I have this code currently:

Code: Select all

if hours < 4 or hours > 22 then
	entity.active = false
end
if hours >= 4 or hours <= 22 then
	entity.active = true
end
where I have a local variable entity and I give it the path to my entity lua file, however the machine does not stop working. I tried the code in, and outside of a loop, both of them don't work. I also tried

Code: Select all

set_frozen(entity[, mode=true]
however Factorio doesn't like the comma and gives me error that it was expecting something near comma.
To get the time, I am using similar code to StatsGUI because I know that works and I haven't found documentation on the game time, maybe I was searching in wrong place.
well the

Code: Select all

[, mode=true]
means optional, you either remove this competely or include it as intended

so it should be like

Code: Select all

set_frozen(entity)
-- or
set_frozen(entity,true)
-- or
set_frozen(entity,false)
depand on what effect you want.

CryptoCat
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Nov 06, 2021 1:52 am
Contact:

Re: Make machine only work during day time

Post by CryptoCat »

meifray wrote:
Sat Nov 06, 2021 7:32 pm

well the

Code: Select all

[, mode=true]
means optional, you either remove this competely or include it as intended

so it should be like

Code: Select all

set_frozen(entity)
-- or
set_frozen(entity,true)
-- or
set_frozen(entity,false)
depand on what effect you want.
Thank you for clarification.
After correcting it, the machine still does not stop when it turns night. Do I have to put in in a while true do loop? I have a suspicion that the time never gets updated, and therefore the machine doesn't turn off.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Make machine only work during day time

Post by PFQNiet »

Can you name a time when "hours >= 4 or hours <= 22" won't be true?

Just replace that entire second "if" line with the single word "else".

Post Reply

Return to “Modding help”