Page 1 of 1
Make machine only work during day time
Posted: Sat Nov 06, 2021 2:00 am
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
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 8:10 am
by meifray
no worries,you can just set it to very small value,it just not accept 0.
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 9:27 am
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.
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 9:39 am
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?
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 11:35 am
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.
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 7:06 pm
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
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.
Re: Make machine only work during day time
Posted: Sat Nov 06, 2021 7:32 pm
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
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
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.
Re: Make machine only work during day time
Posted: Sun Nov 07, 2021 1:53 am
by CryptoCat
meifray wrote: ↑Sat Nov 06, 2021 7:32 pm
well the
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.
Re: Make machine only work during day time
Posted: Sun Nov 07, 2021 2:12 am
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".