1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Melee Mapping contest #3 - Poll is up! Vote for the best 4v4 melee maps!
    Dismiss Notice
  3. The 30th edition of the Modeling Contest is finally up! The Portable Buildings need your attention, so come along and have a blast!
    Dismiss Notice
  4. We have a new contest going on right now! Join the 11th Music Contest! You are to make a Cinematic modern sound-track for this contest, so come and compete with other people for fun.
    Dismiss Notice

.txtFile v4.0

Submitted by NEL
This bundle is marked as approved. It works and satisfies the submission rules.

  • .txtFile v4.0

    Allows to create a clean text file using Batch Script.



      1. Go to the Preferences menu and make sure "Automatically create unknown variables while pasting trigger data" is checked.
      2. Copy and Paste the txtFile trigger and txtFile Variable Creator trigger to your map.
      3. Once you've copied all triggers, delete txtFile Variable Creator trigger in your map.




        • GUI Sample
          • Events
            • Player - Player 1 (Red) types a chat message containing -guisave as An exact match
            • Player - Player 2 (Blue) types a chat message containing -guisave as An exact match
          • Conditions
          • Actions
            • -------- ========================================================= --------
            • -------- Filename --------
            • Set txtFile_Filename = SampleGUI
            • -------- ========================================================= --------
            • -------- Directory --------
            • -------- => If you want to add subfolder, just add "\". --------
            • Set txtFile_Folder = SampleGUI\YouCanCreateASubFolder
            • -------- ========================================================= --------
            • -------- Targeted Player --------
            • -------- => If you want to affect to all players, remove this variable or set null. --------
            • Set txtFile_Player = (Triggering player)
            • -------- ========================================================= --------
            • -------- Write --------
            • Set txtFile_Line[1] = txtFile_Line is a 1 Based Array
            • Set txtFile_Line[2] = You can print an empty line.
            • Set txtFile_Line[3] = <Empty String>
            • Set txtFile_Line[4] = Or you can skip a line
            • Set txtFile_Line[6] = <Empty String>
            • Set txtFile_Line[7] = Also this system is UNICODE Supported
            • Set txtFile_Line[8] = <Empty String>
            • Set txtFile_Line[9] = <Empty String>
            • Set txtFile_Line[10] = CurrentDate: %DATE% TIME: %timeNow%
            • Set txtFile_Line[11] = <Empty String>
            • Set txtFile_Line[12] = <Empty String>
            • -------- Close it --------
            • Set txtFile_Total = 12
            • -------- ========================================================= --------
            • -------- Run .txtFile --------
            • Custom script: call ExecuteFunc("txtFile")


      • Code (vJASS):
        function Trig_Unicode_Actions takes nothing returns nothing
            local player pl = GetTriggerPlayer()

            // =========================================================
            // Configuration
           
            // > Filename
            set udg_txtFile_Filename = "boo" + "_" + GetPlayerName(pl)
           
            // > Directory
            set udg_txtFile_Folder = "foo"
           
            // > Targeted Player
            set udg_txtFile_Player = pl
               
            // =========================================================
            // Write
            set udg_txtFile_Line[1] = "안녕하세요 세계"
            set udg_txtFile_Line[2] = "Korean"
            set udg_txtFile_Line[3] = ""
            set udg_txtFile_Line[4] = "こんにちは世界"
            set udg_txtFile_Line[5] = "Japanese"
            set udg_txtFile_Line[6] = ""
            set udg_txtFile_Line[7] = "Привет, мир"
            set udg_txtFile_Line[8] = "Russian"
            set udg_txtFile_Line[9] = ""

            // Close
            set udg_txtFile_Total = 10
               
            // =========================================================
            // Run
            call ExecuteFunc("txtFile")
           
            // =========================================================
            // Clean
            set pl = null
        endfunction

        //===========================================================================
        function InitTrig_Unicode takes nothing returns nothing
            set gg_trg_Unicode = CreateTrigger(  )
            call TriggerRegisterPlayerChatEvent( gg_trg_Unicode, Player(0), "-create", true )
            call TriggerRegisterPlayerChatEvent( gg_trg_Unicode, Player(1), "-create", true )
            call TriggerAddAction( gg_trg_Unicode, function Trig_Unicode_Actions )
        endfunction


         





  • Pure JASS Code.

    Code (vJASS):
    // *********************************************************************************
    // *
    // *
    // *    .txtFile v4.0
    // *       by nel | NELMVN
    // *  
    // *    Allows to create a clean text file using Batch Script.
    // *  
    // *
    // **********************************************************************************
    // *
    // *    Variable API:
    // *
    // *       string udg_txtFile_Filename          (Required)
    // *          -> Filename of a text file.
    // *
    // *       string udg_txtFile_Folder            (Required)
    // *          -> Directory of a text File.
    // *
    // *       string array udg_txtFile_Line        (Optional)
    // *          -> Write line by line. This variable is a 1 based array.
    // *
    // *       integer udg_txtFile_Total            (Required)
    // *          -> Number of lines.
    // *
    // *       player udg_txtFile_Player            (Optional)
    // *          -> Owner of a text file. Set null to affect to all players.
    // *
    // *       -------------------------------------------------------------------------
    // *      
    // *       The following constant batch script variables are only works inside of a
    // *       udg_txtFile_Line:
    // *
    // *       %dMonth%
    // *          -> Current Month.
    // *
    // *       %dDay%
    // *          -> Current Day.
    // *
    // *       %dYear%
    // *          -> Current Year.
    // *
    // *       %dWeek%
    // *          -> Current Week.
    // *
    // *       %DATE%
    // *          -> Current Date (mm/dd/yyyy format)
    // *
    // *       %timeNow%
    // *          -> Current Time (12 hours format)
    // *
    // *       %TIME%
    // *          -> Current Time (24 hours format)
    // *
    // **********************************************************************************
    // *
    // *    Function:
    // *
    // *       call ExecuteFunc("txtFile")          (Required)
    // *          -> Execute the txtFile System.
    // *
    // **********************************************************************************
    // *
    // *    Limitation:
    // *       -> This system is only works in Windows 0S.
    // *       -> Each line, you can only put 235 characters (Including the Batch Script
    // *          Command). Once a line had excess characters, it will print them in the
    // *          next line.
    // *       -> There are few forbidden characters in Batch Script are not supported.
    // *
    // **********************************************************************************
    // *
    // *    SETTINGS
    // *
    // *    Display the current date and time at the bottom of a text file.
        constant function txtFile_dateTime takes nothing returns boolean
            return true
        endfunction
    // *
    // *    Auto-Open Notepad.
        constant function txtFile_autoOpen takes nothing returns boolean
            return true
        endfunction
    // *
    // *    Error Message.
    // *    Set true, if you want to display an Error message in-game.
        constant function txtFile_Err takes nothing returns boolean
            return true
        endfunction
    // *
    // **********************************************************************************


    constant function txtFile_MAX_CHAR_PRELOAD takes nothing returns integer
        // Preload can handle up to 259 characters.
        return 235
    endfunction

    constant function txtFile_MAX_CHAR_FILENAME takes nothing returns integer
        // https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
        return 204
    endfunction

    function txtFile_ErrMsg takes string Description returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 0, "[|cffff0000.txtFile Error|r] " + Description)
    endfunction

    function txtFile_Windows_SpecialChar takes string Text, boolean isFolder returns boolean
        local integer Index = 1
        local boolean error = false
        local string Char
       
        // String Length & Null Value
        if StringLength(Text) == 0 or Text == null then
            set error = true
           
            if txtFile_Err() then
                if isFolder then
                    call txtFile_ErrMsg("Folder name has no value.")
                else
                    call txtFile_ErrMsg("Filename has no value.")
                endif
            endif

        elseif SubString(Text, 0, 1) == "\\" and isFolder then
            set error = true
           
            if txtFile_Err() then
                call txtFile_ErrMsg("You're not allowed to use \"|cffffff00\\|r\" as Folder name.")
            endif
           
        elseif SubString(Text, StringLength(Text) - 1, StringLength(Text)) == "\\" and isFolder then
            set error = true
           
            if txtFile_Err() then
                call txtFile_ErrMsg("SubFolder has no value.")
            endif
           
        else
            // A file name can't contain any of the following characters:
            //        \ / : * ? " < > |
            loop
                exitwhen Index > StringLength( Text) or error

                set Char = SubString(Text, Index - 1, Index)
               
                if Char == "\\" and not isFolder then
                    set error = true
                elseif Char == "/" then
                    set error = true
                elseif Char == ":" then
                    set error = true
                elseif Char == "*" then
                    set error = true
                elseif Char == "?" then
                    set error = true
                elseif Char == "\"" then
                    set error = true
                elseif Char == "<" then
                    set error = true
                elseif Char == ">" then
                    set error = true
                elseif Char == "|" then
                    set error = true
                endif
               
                set Index = Index + 1
               
                if txtFile_Err() and error then
                    if Char == "\\" and not isFolder then
                        call txtFile_ErrMsg("Using \"|cffffff00" + Char + "|r\" in Folder name is forbidden.")
                    else
                        if isFolder then
                            call txtFile_ErrMsg("Using \"|cffffff00" + Char + "|r\" in Folder name is forbidden.")
                        else
                            call txtFile_ErrMsg("Using \"|cffffff00" + Char + "|r\" in Filename is forbidden.")
                        endif
                    endif
                endif
            endloop

            set Char = null
        endif

        return error
    endfunction

    function txtFile_Windows_SpecialName takes string Text returns boolean
        // Do not use the following reserved names for the name of a file:
        // CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7,
        // COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8,
        // and LPT9
        if Text == "CON" then
            return true
        elseif Text == "PRN" then
            return true
        elseif Text == "AUX" then
            return true
        elseif Text == "NUL" then
            return true
        elseif Text == "COM1" then
            return true
        elseif Text == "COM2" then
            return true
        elseif Text == "COM3" then
            return true
        elseif Text == "COM4" then
            return true
        elseif Text == "COM5" then
            return true
        elseif Text == "COM6" then
            return true
        elseif Text == "COM7" then
            return true
        elseif Text == "COM8" then
            return true
        elseif Text == "COM9" then
            return true
        elseif Text == "LPT1" then
            return true
        elseif Text == "LPT2" then
            return true
        elseif Text == "LPT3" then
            return true
        elseif Text == "LPT4" then
            return true
        elseif Text == "LPT5" then
            return true
        elseif Text == "LPT6" then
            return true
        elseif Text == "LPT7" then
            return true
        elseif Text == "LPT8" then
            return true
        elseif Text == "LPT9" then
            return true
        else
            return false
        endif
    endfunction

    function txtFile_Print takes nothing returns nothing
        local integer Length
        local integer Index = 1
        local integer IndexB = 0
        local real excessCount
        local real excessCalc
        local string Line
       
        if GetLocalPlayer() == udg_txtFile_Player or udg_txtFile_Player == null then
            // Initialize Preloader
            call PreloadGenClear()
            call PreloadGenStart()
            call Preload("\r\n@ECHO OFF\r\nCLS\r\n::")
            call Preload("\r\nSET E=" + udg_txtFile_Filename + "\r\n::")
           
            // Delete the existing file.
            call Preload("\r\nIF exist %E%.txt (\r\n    DEL %E%.txt\r\n)\r\n::")
           
            // Date & Time
            call Preload("\r\nFor /f \"tokens=1-4 delims=/ \" %%a in ('date /t') do (\r\n    set dMonth=%%a\r\n    set dDay=%%b\r\n    set dYear=%%c\r\n    set dWeek=%%d\r\n)\r\n::")
            call Preload("\r\nFor /f \"tokens=1-2 delims=/:\" %%a in ('time /t') do (set timeNow=%%a:%%b)\r\n::")
           
            // File Encoding: ANSI to Unicode
            // Source: https://ss64.com/nt/type.html
            call Preload("\r\nIF exist N.txt (\r\n    DEL N.txt\r\n)\r\n::")
            call Preload("\r\nFor /f \"tokens=2 delims=:\" %%G in ('CHCP') do Set _codepage=%%G\r\n::")
            call Preload("\r\nCHCP 1252 >NUL\r\n::")
            call Preload("\r\nCMD.EXE /D /A /C (SET/P=yþ)<NUL > N.txt 2>NUL\r\n::")
            call Preload("\r\nBREAK > N.txt\r\n::") // Clear N.txt
           
            loop
                exitwhen Index > udg_txtFile_Total
                set Length = StringLength(udg_txtFile_Line[Index])

                if Length > 0 then
                    if Length > txtFile_MAX_CHAR_PRELOAD() then
                        set IndexB = txtFile_MAX_CHAR_PRELOAD()
                        set excessCalc = I2R(Length) / I2R(txtFile_MAX_CHAR_PRELOAD())
                        set excessCount = excessCalc

                        loop
                            exitwhen excessCount < 1
                            set Line = SubString(udg_txtFile_Line[Index], IndexB - txtFile_MAX_CHAR_PRELOAD(), IndexB)
                            call Preload("\r\n@ECHO " + Line + ">>N.txt\r\n::")

                            set IndexB = IndexB + txtFile_MAX_CHAR_PRELOAD()
                            set excessCount = excessCount - 1.
                        endloop

                        if excessCount > 0 then
                            set Line = SubString(udg_txtFile_Line[Index], R2I(excessCalc) * txtFile_MAX_CHAR_PRELOAD(), Length)
                            call Preload("\r\n@ECHO " + Line + ">>N.txt\r\n::")
                        endif

                        // Clean
                        set Line = null
                    else
                        call Preload("\r\n@ECHO " + udg_txtFile_Line[Index] + ">>N.txt\r\n::")
                    endif
       
                    // Clean
                    set udg_txtFile_Line[Index] = null
                else
                    call Preload("\r\n@ECHO: >>N.txt\r\n::")

                    if udg_txtFile_Line[Index] != null then
                        set udg_txtFile_Line[Index] = null
                    endif
                endif
               
                set Index = Index + 1
            endloop
           
            if txtFile_dateTime() then
                call Preload("\r\n@ECHO DATE:    %dMonth%-%dDay%-%dYear% %dWeekend%>>N.txt\r\n::")
                call Preload("\r\n@ECHO TIME:    %timeNow%>>N.txt\r\n::")
            endif

            call Preload("\r\nCHCP %_codepage%\r\nRENAME N.txt %E%.txt\r\n::")
           
            if txtFile_autoOpen() then
                call Preload("\r\nSTART notepad.exe \"%E%.txt\"\r\n::")
            endif
           
            // Close Preloader
            call Preload("\r\nCLS\r\nDEL %E%.bat\r\n::")
            call PreloadGenEnd(udg_txtFile_Folder + "\\" + udg_txtFile_Filename + ".bat")
           
            // Clean
            set Line = null
        endif
    endfunction

    function txtFile_Status takes nothing returns boolean
        local boolean Good

        if udg_txtFile_Player != null then
            if not (GetPlayerId(udg_txtFile_Player) <= bj_MAX_PLAYERS - 1) then
                set udg_txtFile_Player = null
            endif
        endif

        if txtFile_Windows_SpecialName(udg_txtFile_Filename) then
            set Good = false
           
            if txtFile_Err() then
                call txtFile_ErrMsg("|cffffff00" + udg_txtFile_Filename + "|r is a reserved name.\n\n")
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 0, "|cffffff00Do not use the following reserved names for the name of a file:|r")
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 0, "CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9\n\n")
            endif
           
        elseif txtFile_Windows_SpecialName(udg_txtFile_Folder) then
            set Good = false
           
            if txtFile_Err() then
                call txtFile_ErrMsg("|cffffff00" + udg_txtFile_Folder + "|r is a reserved name.\n\n")
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 0, "|cffffff00Do not use the following reserved names for the name of a file:|r")
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 0, "CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9\n\n")
            endif
           
        elseif txtFile_Windows_SpecialChar(udg_txtFile_Filename, false) then
            set Good = false

        elseif txtFile_Windows_SpecialChar(udg_txtFile_Folder, true) then
            set Good = false

        elseif udg_txtFile_Total <= 0 then
            set Good = false
           
            if txtFile_Err() then
                call txtFile_ErrMsg("Value of txtFile_Total is invalid.")
            endif
        else
            // No Error
            set Good = true
        endif
       
        return Good
    endfunction

    function txtFile takes nothing returns nothing
        if txtFile_Status() then
            if StringLength(udg_txtFile_Filename) > txtFile_MAX_CHAR_FILENAME() then
                set udg_txtFile_Filename = SubString(udg_txtFile_Filename, 0, txtFile_MAX_CHAR_FILENAME())
            endif
       
            call txtFile_Print()
        else
            if txtFile_Err() then
                call txtFile_ErrMsg(".txtFile was interrupted.")
            endif      
       
            // Clean
            if udg_txtFile_Folder != null then
                set udg_txtFile_Folder = null
            endif
           
            if udg_txtFile_Filename != null then
                set udg_txtFile_Filename = null
            endif
           
            if udg_txtFile_Player != null then
                set udg_txtFile_Player = null
            endif
        endif
    endfunction

    function InitTrig_txtFile takes nothing returns nothing
        set udg_txtFile_Filename = null
        set udg_txtFile_Folder = null
        set udg_txtFile_Line[0] = null
    endfunction

     




  • [ v4.0 ]
    - Code Reworked.
    - NEW: Unicode Supported

    [ v3.4 ]
    - Fixed _Compile Function.
    - Changed the value of GetPlayerId( udg_txtFile_Player) 11 to 23.
    - You can now able to use Special Characters.
    - Fixed Batch Script Codes.

    [ v3.3 ]
    - Fixed _Compile Function.

    - Error Message
    - Fixed _Create Function. No longer displaying "o" bug in txt file.

    [ v3.2 ]
    - Fixed _Compile Function.
    - Fixed _checkString Function.
    - Fixed _Create Function.

    - Each lines has a maximum of 238 characters.
    - Batch Script: Download a text is much faster than before.
    - No longer to add ":" each lines.
    - Batch Script: Using "echo." to avoid displaying "ECHO is on." without using ":".

    [ v3.1 ]
    - Less code.
    - Fixed _checkString Function. Now you can able to add subfolder in txtFile_FolderName using "\" with no error.
    - Fixed _Compile Function.
    - Fixed _Create Function.
    - Fixed the Documentation.
    - Added Auto-Open Notepad.

    [ v3.0 ]
    - Code Reworked

    [ v2.0 ]
    - Removed txtFile_ChangeLine
    - Added GetLocalPlayer()
    - Trying to avoid reaching more than 259 characters each Preload()

    [ v1.0 ]
    - Release

Contents

.txtFile (Map)

Reviews
IcemanBo
The config should be defined once instead of assigned each trigger run. The trigger could directly run logics without the middle-function which is just called to execute the real logics. Does writing new/empty lines ( no 'space') work? I like...
  1. Reventhous

    Reventhous

    Joined:
    May 2, 2015
    Messages:
    105
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Quite useful :)
    here's my quick suggestion

    -idk but have you indent your code. If not, indent it.
    -the system name is .txtFile that refers a system that can create, edit and delete. (is this possible?, I haven't try Preload things :D )
    -this should be better in JASS (not custom scripts). Unless, you want to keep the variable creator.

    ...can this system store game log...
     
  2. Dark_Axl

    Dark_Axl

    Joined:
    Dec 12, 2007
    Messages:
    472
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    Debug I/O by Almia is already designed to do that, though it need fix as the original script has lots of typos.

    ontopic about the submission,
    - how to use the resource? how to choose what filename? where to save? I can see you provide txt_Filename and txt_Folder, but what value do users have to input there?
    - what options do users have to customize it? (if any customization available aside from filename and folder location)
    - this is really similar to Debug I/O (provided in link above) earlier version, and can be used for the same purpose, what is this resource do better than the other one? (except that its designed in GUI)
    - do Preloadxxx native works well in local player block? have you tested in multiplayer? won't it cause desync? or is this is solely for singleplayer?
    - the "result" you provided looks like how user use this resource, how's the output? attach the screenshot of the result to the main post please so potential users can see the input and output of this resource.
    - we can say that this is aimed to GUI users, you should provide sample of how to use it in GUI too
     
  3. NEL

    NEL

    Joined:
    Mar 6, 2017
    Messages:
    97
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Thanks your suggestions.
     
  4. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,410
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    wait wait wait
    Why is this long script needed?
    I can make a txt file with whatever string with 3-4 lines.
     
  5. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,821
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Have done code for same goal TextFile.
     
  6. XSpectral

    XSpectral

    Joined:
    Sep 29, 2010
    Messages:
    12
    Resources:
    0
    Resources:
    0
    can the system load from that txt?
     
  7. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,432
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    Would you be able to take this one, IcemanBo? The concept is beyond my abilities.
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,821
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    • The config should be defined once instead of assigned each trigger run.

    • The trigger could directly run logics without the middle-function which is just called to execute the real logics.

    • Does writing new/empty lines ( no 'space') work?

    • I like the security mechanics for chars and size.

    • Behaviour what happens if the player variable isn't maintained by user should be explained.

    • if expression == true
      ->
      if expression

      if expression == false
      ->
      if not expression


    • SubString( str, Index - 1, Index)
      can be stored into a variable, for performance.

    • Margin and date seems like a cool extra feature.

    @KILLCIDE

    If empty lines work, it does work at current state, and you agree, it could be approved from my side. 4/5!