V
V
Vladimir Lobanov2022-04-09 17:43:09
C++ / C#
Vladimir Lobanov, 2022-04-09 17:43:09

How to add method to public class from another script?

Task: add a method to the public class Game

public void VehicleMaxFuel(float value)
  {
    bool flag = this._vehicle != null;
    if (flag)
    {
      this._vehicle.maxFuel = value;
    }
  }

Moreover, the public class Game in the compiled modkit library and in this context, editing the library will not lead to anything because the VehicleMaxFuel method is not there, as well as in the game itself, it is not there either, but you need to add it as a script so that it compiles into my library and is loaded game from there. And one more thing: _vehicle is I don't even know if I can do anything with it. private Game.VehicleData _vehicle = null;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Morrowind, 2022-04-09
@Stealch

Hey!
It is not clearly written what is where and why.
If I understand correctly, you need to use the VehicleMaxFuel() method .
Option 1: Create an instance of the class containing the method and that's it.

Game testclass = new Game();
testclas.VehicleMaxFuel()

Option 2: if you want the same class but a different implementation, then you can use inheritance from the class in the mod. In this case, you can use the methods of the parent class (which with the VehicleMaxFuel() method)
public class MyClass : ModClass
{
public void VehicleMaxFuel(float value) {....}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question