Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
So basically I came up with a simple way to keep track on struct instances and how to update them.
Not quite sure if it would be acceptable in the spell section though. Opinions?
Not quite sure if it would be acceptable in the spell section though. Opinions?
JASS:
//! zinc
library TEST{
struct X{
static integer instances = -1;
method onDestroy(){
instances -= 1;
}
method doStuff(){
BJDebugMsg(I2S(this) + ": " + I2S(GetRandomInt(1,10)));
}
static method Update(){
integer i = instances;
while(i >= 0){
thistype(i).doStuff();
i -= 1;
}
}
static method create() -> thistype{
thistype this = thistype.allocate();
instances += 1;
return this;
}
static method onInit(){
TimerStart(CreateTimer(), 0.75, true, function thistype.Update);
}
}
function onInit(){
X.create();
X.create();
X.create();
}
}
//! endzinc