Community Forum

RPM consuming

Forum Overview >> Scripting

CategoryScripting
Created12.04.2021 04:00


Leigh Mike (LesiuApple) 12.04.2021 04:00
Hello everyone, I wonder if I can turn off the increasing in RPM to the maximum when turning on the implement, which function is responsible for it because I can't find it anywhere. I need to turn off it to specific implement. Thanks in advance ;)

Leigh Mike (LesiuApple) 13.04.2021 01:46
OK, I found it but there is a new problem, I don't understand why a simple function override doesn't work, and if I overwrite it globally, everything works as I would like, but for all implements not only for the one for which I want to overwrite this function.

https://ibb.co/k2ScMxV

Bilbo Beutlin (BBeutlin) 13.04.2021 10:31
In your example 'modName.getDoConsumePtoPower()' the function is local to class 'modName' and doesn't touch the global spec function 'PowerConsumer.getDoConsumePtoPower()'.

To modify existing functions system friendly use
oldFunc = Utils.overwrittenFunction(oldFunc, newFunc)
This will prevent from errors or even crashes if other mods touch this function also.

Leigh Mike (LesiuApple) 13.04.2021 11:38
Yes, I know, because I want to override, and specifically disable this function for a given modification that has this specialization.Do I have to override this function globally? I do not know how to disable this function globaly only for a given specialization or for a given condition that my specialization meets.

Bilbo Beutlin (BBeutlin) 13.04.2021 12:02
Yes, you must overwrite it globally, since it is called by the specialization's function dispatcher. Use
PowerConsumer.getDoConsumePtoPower = Utils.overwrittenFunction( PowerConsumer.getDoConsumePtoPower , myMod.myNewFunc )
In your function you can test for 'self.spec_mySpec' and proceed dependingly.

Leigh Mike (LesiuApple) 13.04.2021 13:29
I think I get it. But when I make something like that (https://ibb.co/rkBMjSb) I get errors attempt to index local 'spec' (a nil value).

Thanks in advance.

Bilbo Beutlin (BBeutlin) 13.04.2021 13:47
What I said above: certainly you must check the result for 'nil' before you proceed since other vehicles don't have your 'spec_mySpec'.

Leigh Mike (LesiuApple) 13.04.2021 15:17
I guess you meant something like this. Now the base vehicles work normally, but the one with my specialization responds to the first and second arguments at the same time, which means practically no changes to the unwritten function.

function mySpec:getDoConsumePtoPower(superFunc)
if self.spec_mySpec ~= nil then
return false
else
return self.getIsTurnedOn ~= nil and self:getIsTurnedOn()
end;
end;

Bilbo Beutlin (BBeutlin) 13.04.2021 15:58
Simply use/overwrite getPtoRpm() and return 0 if the vehicle has your spec.

Leigh Mike (LesiuApple) 13.04.2021 16:41
I don't want to bother you with such stupid problem anymore, but unfortunately it still listens to two arguments even when it doesn't overwrite getPtoRpm globally and I just return 0.

https://ibb.co/k0PWLt2

Bilbo Beutlin (BBeutlin) 13.04.2021 20:49
If you have added your spec to a vehicle with spec 'PowerConsumer', the overwritten function is perhaps executed twice: first by the orig. spec, second by yours. Depends on kind how you added the spec.


Note: Log in to post. Create a new account here.