4

about:

Blizzard Warcraft III [furthermore abbreviated as WC3]
related version: WC3: The Frozen Throne 1.26.0.6401 (german Patch 1.26a)
MindWorX Sharpcraft [furthermore abbreviated as SC]
related version: 1.2.4.0

issue:

I'm trying to use the native "TimerStart" from the WC3 "common.j" package inside a SC plugin written in C#. what gives me problems is the last argument from the native ("code handlerFunc"). as there is no native for creating functions, I dont know how to use it properly, can you give an example? for reference of the "code"-argument (it isnt even declared in the "common.j") i used Vexorians thread on wc3c.net, part: "I. The code type". here is the native like declared in "common.j":

native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

in the SC plugin I initialized the native like this:

private delegate void TimerStartPrototype(JassTimer whichTimer, JassRealArg timeout, JassBoolean periodic, JassCode handlerFunc);
private static TimerStartPrototype TimerStart = WarcraftIII.Jass.GetNative("TimerStart").ToDelegate<TimerStartPrototype>();
//native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

additionally in SC plugin, I created a void to pass to the last argument of the native: (note that "StopCamera" is another native from "common.j" i also initialized in the SC plugin but not showing here, because it is done in the same way "TimerStart" was.)

private delegate void StopCameraFuncPrototype();
private void StopCameraFunc() {
    StopCamera();
}

usage of the native "TimerStart" in SC plugin: (note that the variable "jTim_mouseWheel" is a "JassTimer" created somewhere else in the SC plugin.)

TimerStart(jTim_mouseWheel, (JassRealArg)0.01, false, (JassCode)StopCameraFunc());

when im trying to run WC3 with SC, the SC console window prints that it couldnt compile the appropriate plugin *.cs-file due to not being able to convert void to JassCode. by simply renaming "void" into "JassCode" I get the error, that not all code paths return a value...

1 Answers1

2

The JassCode type is only there as a placeholder, and it doesn't have any actual use right now. The code type from JASS is a pointer to a function in a maps compiled JASS script.

I have tried creating new JASS script code at run-time, but I haven't had any good success so far.

Since you're using 1.2.4 there is really no way to achieve what you want. If you were to switch to 2.2.5.124b you'd be able to use the system for attaching C# delegates to a JassTrigger with the following code.

var trigger = JassTrigger.Create();
trigger.RegisterTimerEvent(0.01f, true);
trigger.AddAction(new DelegateAction((JassTrigger theTrigger) => { 
    /* do stuff here */
}));
William
  • 2,724
  • 1
  • 22
  • 24