Closed WilcoDW closed 8 years ago
there is a power-tag in furniture.xml that adds or subtracts power. Look at power generator and gas generator
Yes, but can you change that value during runtime?
Doesn't looks like you can, except for building more machines
it's public so i think you can change it in lua otherwise add a method which changes the powerLevel
At the moment the only Lua connection I considered was being able to check if it had power or not. But last time I checked it was a public field... so you should be able to change it, i think?
and beaten to it :smile:
What were you planning on doing with it, may i ask?
I just tried to do
powerValue = 5
or 0, and MoonSharp said this:
ScriptRuntimeException: attempt to index a nil value
MoonSharp.Interpreter.Execution.VM.Processor.ExecIndex (MoonSharp.Interpreter.Execution.VM.Instruction i, Int32 instructionPtr)
MoonSharp.Interpreter.Execution.VM.Processor.Processing_Loop (Int32 instructionPtr)
I am going to work on implementing it, so i can change the power value
@wilcomega You need to do this:
function OnUpdate_SomeFurniture( furniture, deltaTime )
furniture.powerValue = 5
end
Atleast it worked for me, but it cant power itself because in HasPower it checks if this is a PowerSupply and than returns false...
Yeah if its a consumer then it should have a negative value.
I am also not sure what effects changing the powerValue
during play might have at the moment. So in that regards it will be an interesting experiment.
I used it on the oxygengenerator update function and set it's powerlevel to 5, itself had no power but it could power the metalsmelter ^^
haha, well that's one way to get more generators :laughing:
yeah more power but less oxygen ;D
There is always a price :smiling_imp:
hmm I suspect it will probably pay to put some checks in there somewhere for when the powerValue has been changed so that it updates things, as I don't think changing it at the moment will do anything useful.
At the moment once its in the list of power consumers then the only time it is removed is when you remove the object itself. Perhaps if the value is changed it should have to re-register the furniture with the power system to clean it up :thought_balloon:
Yeah i saw that too ;/
Well it was a basic implementation to get it running, I did not think about the powerValue
being changed when I wrote it and I expected most of it to be changed sooner or later anyway :smile:
@TheRiven @relinu I do not really get why it is necessary to change power Value
on fly?
I was wondering the same as @Grenkin1988
a power generator might not always have the resources, like sunlight, coal or hydrogen needed to generate power, if not it will not generate any power and set its power value to 0, and some machines only need to request power when they have a job to do like smelt iron into steel.
A fusion reactor could first need power to start the fusion reaction and after that it generates power
@wilcomega O.K. that makes sense. I am not familiar with lua how you someone going to change power Value? Just set new value directly? Can lua access properties? @TheRiven Would you do this? Or I could try to solve this (possibly I have solution)
As @wilcomega and @relinu said there are probably going to be times when the state of a machine will change, such as upgrades or fuel issues, and with it the power consumption/production.
My thinking was that the simplest solution might be to remove and then re-register the furniture with the power grid. I was looking into this but will need to look at again now that the code has been refactored.
But if you have possible solution @Grenkin1988 then I say give it a go :+1:
In this pull request i made it so the Power Generator requires coal to operate, coal will also spawn now. in Furniture.cs i added a function that sets the power value, even though lua can already access powerValue directly.
powerValue
I believe this should be closed.
Agreed, closing.
i am not too familliar with the codebase yet and was wondering if the powerValue variable is accesable through Lua code in the furniture? I cant really find anything that dictates what Lua code can use.
Thanks!