Make machine only work during day time
Make machine only work during day time
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
"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
Last edited by meifray on Sat Nov 06, 2021 9:38 am, edited 1 time in total.
- Stringweasel
- Filter Inserter
- Posts: 421
- Joined: Thu Apr 27, 2017 8:22 pm
- Contact:
Re: Make machine only work during day time
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.
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
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock |Weasel's Demolition Derby
Official Contributor to Space Exploration
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock |
Official Contributor to Space Exploration
Re: Make machine only work during day time
Why swap entities? Wouldn't it be enough to toggle LuaEntity.active?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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
- Stringweasel
- Filter Inserter
- Posts: 421
- Joined: Thu Apr 27, 2017 8:22 pm
- Contact:
Re: Make machine only work during day time
Why now that would be a much simpler solution! Next time I'll finish my cup of coffee first.Pi-C wrote: ↑Sat Nov 06, 2021 9:39 am Why swap entities? Wouldn't it be enough to toggle LuaEntity.active?
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock |Weasel's Demolition Derby
Official Contributor to Space Exploration
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock |
Official Contributor to Space Exploration
Re: Make machine only work during day time
I have this code currently:
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.
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
Code: Select all
set_frozen(entity[, mode=true]
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
well theCryptoCat wrote: ↑Sat Nov 06, 2021 7:06 pm I have this code currently: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 triedCode: Select all
if hours < 4 or hours > 22 then entity.active = false end if hours >= 4 or hours <= 22 then entity.active = true end
however Factorio doesn't like the comma and gives me error that it was expecting something near comma.Code: Select all
set_frozen(entity[, mode=true]
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.
Code: Select all
[, mode=true]
so it should be like
Code: Select all
set_frozen(entity)
-- or
set_frozen(entity,true)
-- or
set_frozen(entity,false)
Re: Make machine only work during day time
Thank you for clarification.meifray wrote: ↑Sat Nov 06, 2021 7:32 pm
well themeans optional, you either remove this competely or include it as intendedCode: Select all
[, mode=true]
so it should be likedepand on what effect you want.Code: Select all
set_frozen(entity) -- or set_frozen(entity,true) -- or set_frozen(entity,false)
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
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".
Just replace that entire second "if" line with the single word "else".