• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!

DelayedPrinter

Status
Not open for further replies.
Level 6
Joined
Jul 30, 2013
Messages
282
A little utility I use for when i need to print something to the screen but risk printing more than can fit.

will result in output scrolling untill the last line is printed, depending on what you use it for it might do to tweak the constants at the top.

posted here for feedback befoe oficcially submitting

JASS:
library DelayedPrinter uses StaticQueue
// https://github.com/nestharus/JASS/blob/master/jass/Data%20Structures/Queue/StaticQueue/script.j
    struct DelayedPrinter
        implement StaticQueue
       
        private string value
        private static constant real INTERVAL = 0.2
        private static constant integer RUN_LENGTH = 1
       
        private static method doTick takes nothing returns nothing
            local integer i = 0
            local player lp = GetLocalPlayer()
            loop
                exitwhen RUN_LENGTH == i  // maximum number of lines to show per "tick"
                exitwhen first == sentinel // we are out of messages
                call DisplayTimedTextToPlayer(lp, 0, 0, 20, first.value)
                call pop()
                set i = i + 1
            endloop
        endmethod
       
        /** 
        * print text for all players
        */
        public static method print takes string s returns nothing
            set enqueue().value = s
           
        endmethod
       
        /** 
        * print text for only player p
        */
        public static method printPlayer takes player p, string s returns nothing
            if GetLocalPlayer() == p then
                set enqueue().value = s
            endif
        endmethod
   
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterTimerEvent(t, INTERVAL, true)
            call TriggerAddAction(t, function DelayedPrinter.doTick)
        endmethod
    endstruct
endlibrary
 
Status
Not open for further replies.
Top