A new thread for posting bits of pog or mod info that might be handy for others.
Here is my entry:
Suppose you want to create something like a deathscript. TroutDeathScript(hship dying_ship);
This function gets attached to a ship and will be called when some handler task notices the ship is dying.
Like so: Task.Start(“tTrout.TroutDeathScript”);
The only problem is Task.Start does not allow arguments. So there is no way to tell the deathscript what ship is dying.
I had an idea for passing arguments to tasks, and it works. Code is below. Basically, the task is started inside an atomic statement (so it cannot execute), then a state variable is created for the task and properties are attached to the state variable. Then the Atomic block ends and the task is allowed to find the state variable and collect its arguments.
// Called when the b key is pressed by the player.
StartAction()
{
htask new_task;
hstate new_state;
debug Debug.PrintString("Test Taskn");
atomic {
new_task = Task.Start("tTestTask.Tester");
new_state = State.Create(new_task, 1);
Object.AddStringProperty(new_state,"New Name","Hi Mom");
}
Task.Detach(new_task);
}
task Tester()
{
hstate state;
string name;
state = State.Find(Task.Current());
name = Object.StringProperty(state,"New Name");
debug {
Debug.PrintString(name);
Debug.PrintString(" the mission namen");
}
while (1) {
Task.Sleep(Task.Current(),10.0);
}
}
-Gtrout