Name | Type | is_array | initial_value |
//TESH.scrollpos=208
//TESH.alwaysfold=0
library DebugLog /* v1.1
*************************************************************************************
*
* Allows you to print messages in Warcraft 3 In-Game and writes them
* inside a .bat file. Run the .bat file and it will download the text document
* where the messages are written. The messages will be written along with the
* elapsed game time. All .bat files will go to the desired folder you want
* them to be created.
*
*************************************************************************************
*
* API
*
* Struct Log extends array
*
* static method write takes string s returns nothing
* - Prints the messages(if ALLOW_PRINT is true) and writes it in the .bat file
*
* static method clear takes nothing returns nothing
* - Clears all written messages
*
* static method createFile takes nothing returns nothing
* - Creates the .bat file
*
* private static method buffer takes nothing returns nothing
* - records the elapsed game time
* - Auto-creates the file(if ALLOW_PERIODIC is true)
*
*************************************************************************************
*
* Notes:
*
* - Messages must be less than 70 characters
* - MAP_NAME must not have spaces.
* - .bat files will be deleted after downloading the txt file.
*
*************************************************************************************
*
* Settings
*
************************************************************************************/
globals
/************************************************
*
* Map Name
* ------------------------------------------
* Put the map's name here.
* This is for you to easily find where
* the log is.
*
************************************************/
private constant string MAP_NAME = "YourMap"
/************************************************
*
* Folder
* ------------------------------------------
* This is where the log will be created
* Recommended not to be touched
*
************************************************/
private constant string LOG_FOLDER = "Map Errors\\DebugLogs\\"
/************************************************
*
* Allow Print
* ------------------------------------------
* Allows you to print messages in-game not
* just outside.
*
************************************************/
private constant boolean ALLOW_PRINT = true
/************************************************
*
* Allow Periodic
* ------------------------------------------
* Allows you to update the debug file
* periodically.
*
************************************************/
private constant boolean ALLOW_PERIODIC = true
private constant real BUFFER = 1.0 // Recommended value
/************************************************
*
* Print Header
* ------------------------------------------
* Prints a description header for much
* pretty description
************************************************/
private constant boolean PRINT_HEADER = false
endglobals
/*************************************************************************************
*
* Credits
*
* Doctor Gester
* Magtheridon96
* Geries
* Nestharus
*
* Testers
*
* Garfield1337
* mckill2009
* SeriousEnemy
*
*************************************************************************************/
globals
private string array l
private integer i = 0
private timer t = CreateTimer()
private real mil = 0
private integer sec = 0
private integer min = 0
private string lastRecorded
private real looper = 0
endglobals
/*****************************************************
*
* Document Header
*
******************************************************/
private function Header takes nothing returns nothing
call Preload("\")\r\n\techo ************************************************************************************* >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Warcraft 3 Debug Log >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Logs of " + MAP_NAME + " >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * -------------------------------------------------------------------------- >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Statistics: >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * ------------------------------------------ >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Number of Lines : " + I2S(i + 1) + " >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Last Recorded Time : " + lastRecorded + " >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * -------------------------------------------------------------------------- >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * Time: Message: >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
endfunction
private module Init
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
struct Log extends array
static method write takes string s returns nothing
local string mils = I2S(R2I(mil))
local string secs = I2S(sec)
local string mins = I2S(min)
if mil < 10 then
set mils = "0" + mils
endif
if sec < 10 then
set secs = "0" + secs
endif
if min < 10 then
set mins = "0" + mins
endif
set lastRecorded = "[ " + I2S(min) + " : " + secs + " : " + mils + " ]"
set l[i] = "\")r\n\techo * " + lastRecorded + " : " + s + ">> " + MAP_NAME + "Log.txt\r\n\t(\""
if ALLOW_PRINT then
call BJDebugMsg(s)
endif
set i = i + 1
endmethod
static method clear takes nothing returns nothing
local integer id = 0
loop
exitwhen i == id
set l[id] = ""
set id = id + 1
endloop
set i = 0
endmethod
static method createFile takes nothing returns nothing
local integer id = 0
call PreloadGenClear()
call PreloadGenStart()
call Preload("\")\r\n\tDEL " + MAP_NAME + "Log.txt\r\n\t(\"")
if PRINT_HEADER then
call Header()
endif
loop
exitwhen id == i
call Preload(l[id])
set id = id + 1
endloop
if PRINT_HEADER then
call Preload("\")\r\n\techo * >> " + MAP_NAME + "Log.txt \r\n\t(\"")
call Preload("\")\r\n\techo ************************************************************************************* >> " + MAP_NAME + "Log.txt \r\n\t(\"")
endif
call Preload("\")\r\n\tstart " + MAP_NAME + "Log.txt\r\n\t(\"")
call Preload("\")\r\n\tDEL " + "Download" + MAP_NAME + "Log.bat\r\n\t(\"")
call PreloadGenEnd(LOG_FOLDER + "Download" + MAP_NAME + "Log.bat")
endmethod
private static method buffer takes nothing returns nothing
set mil = mil + 3.125000000
if mil > 99 then
set mil = 0
set sec = sec + 1
if sec > 59 then
set sec = 0
set mil = mil + 1
endif
endif
if ALLOW_PERIODIC then
if looper > BUFFER then
set looper = 0
call createFile()
else
set looper = looper + 0.031250000
endif
endif
endmethod
private static method init takes nothing returns nothing
call TimerStart(t, 0.031250000, true, function Log.buffer)
endmethod
implement Init
endstruct
endlibrary
//TESH.scrollpos=5
//TESH.alwaysfold=0
library Test initializer init uses DebugLog
globals
private integer i = 0
private real value = 0
private boolean get = false
endglobals
private function test takes nothing returns nothing
set value = value + 0.003125000
if get then
call Log.write(R2SW(value, 11, 11))
set value = 0.0
set get = false
endif
endfunction
private function init takes nothing returns nothing
call Log.write("Recording Wait values : 0.0 value")
call Log.write("Number of expected record times : 100")
call TimerStart(CreateTimer(), 0.003125000, true, function test)
loop
exitwhen i == 100
set i = i + 1
call TriggerSleepAction(0.0)
set get = true
endloop
endfunction
endlibrary