error CS0120: An object reference is required for the non-static field, method, or property 'DemonicSamurai.Despawn()'

DragnMaw

Citizen
public void Despawn()
{
Delete();
}

public class SpawnTime : Timer
{
public static void Initialize()
{
new SpawnTime().Start();
}

public SpawnTime() : base(TimeSpan.FromMinutes(60))
{
Priority = TimerPriority.OneMinute;
}

public static void OnTick()
{
DemonicSamurai.Despawn();
}
}

Theres the relevent parts of the code. I'm trying to make a mobile only live for 60 minutes, it just keeps erroring out with that error, or "error CS0120: An object reference is required for the non-static field, method, or property 'Mobile.Delete()'" if I set it to public static void Despawn(). I'm guessing I need to pass something from the OnTick to the Despawn, but I have no idea the easiest way to do what I am trying. And I just know this is going to be something really easy to solve.
 

SimonOmega

Citizen
Shouldn't Delete be a method of an object?
Try deleting the base object.

Delete the base object:
public void Despawn()
{
  base.Delete();
}
 

AsYlum

Citizen
Well the error is because you are trying to call instance method .Despawn() on class DemonicSamurai inside static method. To be able to call Despawn you need class instance, an object.

I think you'd be better to create regular non-static SpawnTimer class with parameters as you need and store that SpawnTimer instance on the field inside DemonicSamurai class. When creating DemonicSamurai instance in constructor you create instance of SpawnTimer and it will Despawn mobile when time comes.

Something similar is done here ServUO/ServUO

There is private class SpawnTimer inside RSQEggSac class.