• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] MUI using Struct

Status
Not open for further replies.

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
Do you think I'm doing good or not? Did I allocate and deallocate properly?

vJASS:
        TimerUtils,              /* wc3c.net/showthread.php?t=101322                                           */
        Alloc                    /* github.com/nestharus/JASS/blob/master/jass/Systems/Alloc/Standard/script.j */



    struct Stealth extends array {
        module Alloc; /* optional, maybe */
 
        unit target;
        timer t;

        static method onExpire() {
            integer data = GetTimerData(GetExpiredTimer());
            thistype this = data; /* I'm not sure at this */
     
            UnitRemoveAbility(this.target, STEALTH_DETECTOR_ID );
            ReleaseTimer(this.t);
            this.deallocate();
        }

        static method apply( unit target ) {
            thistype this = thistype.allocate();
     
            this.target = target;
            this.t = NewTimerEx(this);
     
            UnitAddAbility( this.target, STEALTH_DETECTOR_ID );
            TimerStart( this.t, STEALTH_DURATION, false, function thistype.onExpire );
        }
    }

Because I have doubt in thistype this = data and

How to make a periodic loop inside the struct?
 
Last edited:
It's correct, and yes the data is fine. You may also just local thistype this = GetTimerData(GetExpiredTimer());

How to make a periodic loop inside the struct?
It's the "periodic" flag you set here to false :
TimerStart( this.t, STEALTH_DURATION, false, function thistype.onExpire );
.. so you can simply set it to true. And then make some condition inside the callback function, to decide if to continue the run, or to destroy the instance (with timer).
 
  • Like
Reactions: NEL
Status
Not open for further replies.
Top