• 🏆 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!

[Snippet] Debug Log

Level 5
Joined
Dec 6, 2009
Messages
79

JASS:
//@ Debug Log library by DoctorGester, 2011, v 1.0.0.1

// This little system allows you to use preload exploit for saving debug on the hard drive.

// Installation:
//    Create a new trigger, convert it into code, delete existing code and paste Debug Log code into that
//    or just copy Debug Log into the custom code section.

// API:
//    LogAdd(string)
//    - Add string into the log.
//    LogClear()
//    - Clears the log.
//    LogUpdate()
//    - Manually updates the log.

// Requirements:
//    Jass New Gen Pack 5d
//    cJass 1.4.2.27 : [url]http://code.google.com/p/cjass/downloads/list[/url]

library DebugLog{

//Settings:
    #define{
        private SavePath = \\Dir\\Debug
        private AutoSaveLog = true
        private LogSavePeriod = 1.0
    }

//Code:
    #include "cj_types_priv.j"

    private string DebugLog[8192]
    private int CurrentString = 0
    private int Seconds = 0
    private int Minutes = 0
    private constant int StringLimit = 200
    
    void LogAdd(string s){
        string sec = I2S(Seconds)
        if (Seconds < 10){
            sec = "0" + sec
        }
        DebugLog[CurrentString] = DebugLog[CurrentString] + ("[" + I2S(Minutes) + ":" + sec + "] " + s + "\n")
        if (StringLength(DebugLog[CurrentString]) >= StringLimit){
            CurrentString++
        }
    }
    
    optional void LogClear(){
        for(int i = 0; i <= CurrentString; i++){
            DebugLog[i] = ""
        }
        CurrentString = 0
    }
    
    void LogUpdate(){
        PreloadGenClear()
        PreloadGenStart()
        for(int i = 0; i <= CurrentString; i++){
            Preload("\")\n" + DebugLog[i] + "\n(\"")
        }
        PreloadGenEnd(`SavePath` + ".txt")
    }
    
    private void DebugLogOnTimer(){
        Seconds++
        if (Seconds > 59){
            Seconds = 0
            Minutes++
        }
    }

    callback onInit(){
        #if AutoSaveLog
            TimerStart(CreateTimer(), LogSavePeriod, true, function LogUpdate)
        #endif
        TimerStart(CreateTimer(), 1., true, function DebugLogOnTimer)
        LogAdd("By DoctorGester. Last compilation: " + `DATE` + " " + `TIME`)
    }
    
}



JASS:
library DebugLog
    globals
        private constant string SAVE_PATH = "C:\\Users\\"
        private constant boolean AUTO_SAVE = false
        private constant real SAVE_INTERVAL = 1.0
        
        private string array log
        private integer index = 0
        private integer seconds = 0
        private integer minutes = 0
    endglobals
    
    function LogAdd takes string s returns nothing
        local string sec=I2S(seconds)
        if seconds<10 then
            set sec="0"+sec
        endif
        set log[index]="[" + I2S(minutes) + ":" + sec + "] " + s + "\n"
        set index=index+1
    endfunction
    
    function LogClear takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i>index
            set log[i]=""
            set i=i+1
        endloop
        set index = 0
    endfunction
    
    function LogUpdate takes nothing returns nothing
        local integer i=0
        call PreloadGenClear()
        call PreloadGenStart()
        loop
            exitwhen i>index
            call Preload("\")\n" + log[i] + "\n(\"")
            set i=i+1
        endloop
        call PreloadGenEnd(SAVE_PATH+"DebugLog.txt")
    endfunction
    
    private function TimeBuffer takes nothing returns nothing
        set seconds=seconds+1
        if seconds>59 then
            set seconds=0
            set minutes=minutes+1
        endif
    endfunction
    
    private module Init
        private static method onInit takes nothing returns nothing
            static if AUTO_SAVE then
                call TimerStart(CreateTimer(),SAVE_INTERVAL,true,function LogUpdate)
            endif
            call TimerStart(CreateTimer(),1.,true,function TimeBuffer)
        endmethod
    endmodule
    private struct Inits extends array
        implement Init
    endstruct
endlibrary
 
Last edited:
Here:

JASS:
library DebugLog
    globals
        private constant string SAVE_PATH = "C:\\Users\\"
        private constant boolean AUTO_SAVE = false
        private constant real SAVE_INTERVAL = 1.0
        
        private string array log
        private integer index = 0
        private integer seconds = 0
        private integer minutes = 0
    endglobals
    
    function LogAdd takes string s returns nothing
        local string sec=I2S(seconds)
        if seconds<10 then
            set sec="0"+sec
        endif
        set log[index]="[" + I2S(minutes) + ":" + sec + "] " + s + "\n"
        set index=index+1
    endfunction
    
    function LogClear takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i>index
            set log[i]=""
            set i=i+1
        endloop
        set index = 0
    endfunction
    
    function LogUpdate takes nothing returns nothing
        local integer i=0
        call PreloadGenClear()
        call PreloadGenStart()
        loop
            exitwhen i>index
            call Preload("\")\n" + log[i] + "\n(\"")
            set i=i+1
        endloop
        call PreloadGenEnd(SAVE_PATH+"DebugLog.txt")
    endfunction
    
    private function TimeBuffer takes nothing returns nothing
        set seconds=seconds+1
        if seconds>59 then
            set seconds=0
            set minutes=minutes+1
        endif
    endfunction
    
    private module Init
        private static method onInit takes nothing returns nothing
            static if AUTO_SAVE then
                call TimerStart(CreateTimer(),SAVE_INTERVAL,true,function LogUpdate)
            endif
            call TimerStart(CreateTimer(),1.,true,function TimeBuffer)
        endmethod
    endmodule
    private struct Inits extends array
        implement Init
    endstruct
endlibrary

Incase Bribe and Nestharus attack ;)
 
ah ok. i'm jvass noob =)

No your not :p
A noob would be someone who'd do something like this:

JASS:
scope MYSPELL
    globals
        unit MYSPELL_UNIT
        unit MYSPELL_TARGET_UNIT
    endglobals

    function Trig_MYSPELL_Spell_ACTIONS takes nothing returns nothing
        local unit a_unit
        local unit another_UNIT
        set a_unit = GetTriggerUnit()
        set another_UNIT = GetSpellTargetUnit()
        set MYSPELL_UNIT = a_unit
        set MYSPELL_TARGET_UNIT = another_UNIT
        call UnitDamageTargetBJ(MYSPELL_UNIT,MYSPELL_TARGET_UNIT,2222222222,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        if GetLocalPlayer() == GetLocalPlayer() then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,-232432,I2S(S2I(I2S(S2I(I2S(S2I(I2S(2222222222))))))) +  " has been dealt!"
        endif
        set MYSPELL_UNIT = null
        set MYSPELL_TARGET_UNIT = null
    endfunction

    function MYAWESOMECONDITION takes nothing returns boolean
        local integer theAbilityCodeThatIwanttoMakeSureIsEqualtoThisAbilityCode = GetSpellAbilityId()
        if ((theAbilityCodeThatIwanttoMakeSureIsEqualtoThisAbilityCode == 'A000' )) ==   true then
            return true
        elseif (((theAbilityCodeThatIwanttoMakeSureIsEqualtoThisAbilityCode != 'A000' )) == true) then
            return false
        endif
        return false
    endfunction

    function InitTrig_This_TRIGGER takes nothing returns nothing
        set gg_trg_MYSPELL = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_MYSPELL , EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( gg_trg_MYSPELL , Condition( function MYAWESOMECONDITION ) )
        call TriggerAddAction( gg_trg_MYSPELL , function Trig_MYSPELL_Spell_ACTIONS )
    endfunction
endscope

That's what noob code would look like :p

You're close to an adept :p

I'm a vJass adept (Not so good, but not bad either)
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Some install instructions, like telling users they need to "enable
local files" on their hard drive, and also telling users they should
configure the file path, should make this thing approve-worthy.

I plan to use this thing, as it looks very useful. In game text
messages also lag the game because they clog the chat messages.
 
Level 11
Joined
Sep 30, 2009
Messages
697
Looks pretty neat, but what I was always wondering is: Does that preload stuff actually work once/only on map init since it could be used to store the codes for rpg maps so you dont have to look up screenshots and can easily copypasta

EDIT: Nevermind the code looks like it works just perfectly always ^^
 
Top