Community Forum


Forum Overview >> Scripting

Created27.10.2016 02:28

Tykonket (IlMat) 27.10.2016 02:29
What exactly does it do?

Emil Drefers (Unknown) 27.10.2016 09:50

please have a look at the script documentation to see how it is used.
If you do so, you probably understand what it does exactly


Tykonket (IlMat) 27.10.2016 10:57
Hi Emil, thanks for answer.
Would be easier to understand if the Utils API were be completely documented xD
Anyway I found this by reading the code blocks in the scripting docs, but I'm still not sure of what does it do :(

Emil Drefers (Unknown) 28.10.2016 08:02

let's say that a specialization has a function which needs to be altered by another specialization.

In this case the second specialization would use Utils.overwrittenFunction() to modify the default behavior by replacing the original function.
Due to the fact that the original function is passed to the new function the behavior can be adjusted to any cases/circumstances.

An example for the usage of this principles might be:
TurnOnVehicle:getIsTurnedOnAllowed ()

which is overwritten by Foldable.lua:
self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, Foldable.getIsTurnedOnAllowed);

If you think about foldable sowingMachines for example, I guess you understand why that is needed


Tykonket (IlMat) 28.10.2016 12:54
Ok, so if you want totally rewrite the function you only need to do something like that:
self.getIsTurnedOnAllowed = Foldable.getIsTurnedOnAllowed;

But if you want to modify or simply add code to a function you need to use Utils.overwrittenFunction and you'll get the "superFunc" param, right?

I'm sorry but in C# this behaviour is called "Override" not "Overwrite" and I wasn't associating the two.

Last question, what about multiple overwriting?
For example if I do again
self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, MySpecialization.getIsTurnedOnAllowed);
in my mod what will happen?

Emil Drefers (Unknown) 01.11.2016 08:57

right, Utils.overwrittenFunction() can be used to add code to the default scripts/behavior.

You can overwrite Function as much as you want.
Every overwrite will becalled, but only if the superFunc is called.


Tykonket (IlMat) 02.11.2016 14:04
Ok ty

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