• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] InitTrig not running?

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
Currently, I have an issue with this system I'm coding. Apparently the Initialization for the trigger won't run, so I can't tell if the system is coded incorrectly.

EDIT: Updated code posted below as of 3/27/2012 : 4:10

JASS:
library CSV2 initializer Init

    globals
        string array COLOR
        string array COLNUM
        string array REALNAME
        integer array PCOLOR
        force PLAYFORCE
        boolean ALLIES
        boolean ALL
        boolean PRIVATE
        integer WHOPRIVATE
        player SENDPLAYER
        string MESSAGE
        integer PLAYERCOUNT
    endglobals

    scope Start

        function DoMapSetup takes nothing returns nothing
            local integer i = 0
            set COLOR[0] = "|c00ff0000"
            set COLOR[1] = "|c000000ff"
            set COLOR[2] = "|c0000ffff"
            set COLOR[3] = "|c00660099"
            set COLOR[4] = "|c00ffff00"
            set COLOR[5] = "|c00ff6600"
            set COLOR[6] = "|c00ff00ff"
            set COLOR[8] = "|c0000ff00"
            set COLOR[9] = "|c00666666"
            set COLOR[10] = "|c009999ff"
            set COLOR[11] = "|c00336600"
            set COLOR[12] = "|c00000000"
            set COLOR[13] = "|c00990000"
            set COLOR[14] = "|c00999900"
            set COLOR[15] = "|cffffffff"
 //------------------------------------------------       
            set COLNUM[0] = "Red"
            set COLNUM[1] = "Blue"
            set COLNUM[2] = "Teal"
            set COLNUM[3] = "Purple"
            set COLNUM[4] = "Yellow"
            set COLNUM[5] = "Orange"
            set COLNUM[6] = "Pink"
            set COLNUM[7] = "Lgreen"
            set COLNUM[8] = "Gray"
            set COLNUM[9] = "Lblue"
            set COLNUM[10] = "Green"
            set COLNUM[11] = "Brown"
            set COLNUM[12] = "Black"
            set COLNUM[13] = "Maroon"
            set COLNUM[14] = "Gold"
            set COLNUM[15] = "White"
        endfunction

        struct Text extends array
            
            private static method DisplayTextAll takes nothing returns nothing
                local player p = SENDPLAYER
                local integer pnum = GetPlayerId( p )
                local integer i = 0
                local player recP
                loop
                    set recP = Player( i )
                    if IsPlayerInForce( recP, PLAYFORCE ) == true then
                        call DisplayTextToPlayer( recP, 0, 0, ( "(All): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + MESSAGE + "|r" ) )
                    endif
                    set i = i + 1
                    exitwhen i > 11
                endloop
                set p = null
                set recP = null
            endmethod
        
            private static method DisplayTextPrivate takes nothing returns nothing
                local player p = SENDPLAYER
                local integer pnum = GetPlayerId( p )
                local player recP = Player( WHOPRIVATE )
                call DisplayTextToPlayer( recP, 0, 0, ( "(Private): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + MESSAGE + "|r" ) )
                set p = null
                set recP = null
            endmethod
    
            private static method DisplayTextAllies takes nothing returns nothing
                local player p = SENDPLAYER
                local integer pnum = GetPlayerId( p )
                local integer i = 0
                local player recP
                loop
                    set recP = Player( i )
                    if IsPlayerInForce( recP, PLAYFORCE ) == true and IsPlayerAlly( recP, p ) == true then
                        call DisplayTimedTextToPlayer( recP, 0, 0, 8.5, ( "(Allies): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + MESSAGE + "|r" ) )
                    endif
                    set i = i + 1
                    exitwhen i > 11
                endloop
                set p = null
                set recP = null
            endmethod
    
            static method SendMessage takes nothing returns nothing
                if ALLIES == true then
                    call thistype.DisplayTextAllies( )
                    set ALLIES = false
                endif
                if ALL == true then
                    call thistype.DisplayTextAll( )
                    set ALL = false
                endif
                if PRIVATE == true then
                    call thistype.DisplayTextPrivate( )
                    set PRIVATE = false
                endif
            endmethod
        endstruct
    endscope
    
    private function ConvertText takes nothing returns nothing
        local string origString = GetEventPlayerChatString( )
        local string codeString = SubString( origString, 0, 3 )
        local integer end = StringLength( origString )
        local integer isAlly = 0
        set SENDPLAYER = GetTriggerPlayer( )
        if codeString == "-p " then
            set PRIVATE = true
            set WHOPRIVATE = S2I( SubString( origString, 3, 5 ) )
            set MESSAGE = SubString( origString, 3, end )
            return
        else
            set isAlly = isAlly + 1
        endif
        if codeString == "-al" then
            set ALL = true
            set MESSAGE = SubString ( origString, 3, end )
            return
        else
            set isAlly = isAlly + 1
        endif
        if isAlly == 2 then
            set ALLIES = true
        endif
        set MESSAGE = SubString( origString, 0, end )
        call Text.SendMessage( )
        set origString = null
        set codeString = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger( )
        local integer i = 0
        local player p
        call DoMapSetup()
        loop
            if GetPlayerSlotState( Player( i ) ) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController( Player( i ) ) == MAP_CONTROL_USER then
                call TriggerRegisterPlayerChatEvent( t, Player(i), "", false)
            endif
            set i = i + 1
            exitwhen i > 11
        endloop
        call TriggerAddAction( t, function ConvertText )
        set t = null
    endfunction
endlibrary
    scope FormForce initializer init
        private function FormForce takes nothing returns nothing
            local integer i = 0
            local player p
            loop
                set p = Player(i)
                if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
                    call ForceAddPlayer(PLAYFORCE, p)
                endif
                set i = i + 1
                exitwhen i > 11
            endloop
            set p = null
        endfunction
        
        private function init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterTimerEvent(t, .5, false)
            call TriggerAddAction(t, function FormForce)
            set t = null
        endfunction
    endscope
 
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
You don't have to care about the trigger name when you use vJass initializers, just use a private initializer called Init everywhere (or whatever else, but Init makes sense).

Merge the code of InitTrig_Map_Config inside the vJass initializer.
 
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
Usually we use this native function :

JASS:
native TriggerRegisterPlayerChatEvent takes trigger whichTrigger, player whichPlayer, string chatMessageToDetect, boolean exactMatchOnly returns event

I'm not sure this works :

JASS:
call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_CHAT)

At least i've never seen a such code.

Anyway, forget lame GUI initializer like, just use vJass initializers, call them always "Init", and add the prefix "private" to these functions initializers, like i did.
 
Level 9
Joined
Apr 23, 2011
Messages
460
So if I shouldn't be using triggers, how would I apply the TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_CHAT) to the script? Please remember, I basically taught myself vJass.

edit: Here is some updated scripting with the Init placed. However it is not registering any chat event. Anyone have an idea?

JASS:
library CSV2 initializer Init

    globals
        string array COLOR
        string array COLNUM
        string array REALNAME
        integer array PCOLOR
        force PLAYFORCE
        boolean ALLIES
        boolean ALL
        boolean PRIVATE
        integer WHOPRIVATE
        player SENDPLAYER
        string MESSAGE
    endglobals

    scope Start

        function DoMapSetup takes nothing returns nothing
            local player p
            local integer i = 0
            set COLOR[0] = "|c00ff0000"
            set COLOR[1] = "|c000000ff"
            set COLOR[2] = "|c0000ffff"
            set COLOR[3] = "|c00660099"
            set COLOR[4] = "|c00ffff00"
            set COLOR[5] = "|c00ff6600"
            set COLOR[6] = "|c00ff00ff"
            set COLOR[8] = "|c0000ff00"
            set COLOR[9] = "|c00666666"
            set COLOR[10] = "|c009999ff"
            set COLOR[11] = "|c00336600"
            set COLOR[12] = "|c00000000"
            set COLOR[13] = "|c00990000"
            set COLOR[14] = "|c00999900"
            set COLOR[15] = "|cffffffff"
 //------------------------------------------------       
            set COLNUM[0] = "Red"
            set COLNUM[1] = "Blue"
            set COLNUM[2] = "Teal"
            set COLNUM[3] = "Purple"
            set COLNUM[4] = "Yellow"
            set COLNUM[5] = "Orange"
            set COLNUM[6] = "Pink"
            set COLNUM[7] = "Lgreen"
            set COLNUM[8] = "Gray"
            set COLNUM[9] = "Lblue"
            set COLNUM[10] = "Green"
            set COLNUM[11] = "Brown"
            set COLNUM[12] = "Black"
            set COLNUM[13] = "Maroon"
            set COLNUM[14] = "Gold"
            set COLNUM[15] = "White"
            loop
                set p = Player( i )
                if GetPlayerSlotState( p ) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController( p ) == MAP_CONTROL_USER then
                    call ForceAddPlayer( PLAYFORCE, p )
                    set REALNAME[i] = GetPlayerName( p )
                    set PCOLOR[i] = 15
                endif
                set i = i + 1
                exitwhen i > bj_MAX_PLAYER_SLOTS
            endloop
            set p = null
        endfunction

        function InitTrig_Map_Config takes nothing returns nothing
            local trigger t = CreateTrigger( )
            call TriggerAddAction( t, function DoMapSetup )
            set t = null
        endfunction

        struct Text extends array
            private static method DisplayTextAll takes nothing returns nothing
                local player p = SENDPLAYER
                local string s = MESSAGE
                local integer pnum = GetPlayerId( p )
                local integer i = 0
                local player recP
                loop
                    set recP = Player( i )
                    if IsPlayerInForce( recP, PLAYFORCE ) == true then
                        call DisplayTextToPlayer( recP, 0, 0, ( "(All): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + s + "|r" ) )
                    endif
                    set i = i + 1
                    exitwhen i > bj_MAX_PLAYER_SLOTS
                endloop
                set p = null
                set s = null
                set recP = null
            endmethod
        
            private static method DisplayTextPrivate takes nothing returns nothing
                local player p = SENDPLAYER
                local string s = MESSAGE
                local integer pnum = GetPlayerId( p )
                local player recP = Player( WHOPRIVATE )
                call DisplayTextToPlayer( recP, 0, 0, ( "(Private): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + s + "|r" ) )
                set s = null
                set p = null
                set recP = null
            endmethod
    
            private static method DisplayTextAllies takes nothing returns nothing
                local player p = SENDPLAYER
                local string s = MESSAGE
                local integer pnum = GetPlayerId( p )
                local integer i = 0
                local player recP
                loop
                    set recP = Player( i )
                    if IsPlayerInForce( recP, PLAYFORCE ) == true and IsPlayerAlly( recP, p ) == true then
                        call DisplayTextToPlayer( recP, 0, 0, ( "(Allies): " + COLOR[PCOLOR[pnum]] + GetPlayerName( p ) + ": " + s + "|r" ) )
                    endif
                    set i = i + 1
                    exitwhen i > bj_MAX_PLAYER_SLOTS
                endloop
                set p = null
                set recP = null
                set s = null
            endmethod
    
            static method SendMessage takes nothing returns nothing
                if ALLIES == true then
                    call thistype.DisplayTextAllies( )
                    set ALLIES = false
                endif
                if ALL == true then
                    call thistype.DisplayTextAll( )
                    set ALL = false
                endif
                if PRIVATE == true then
                    call thistype.DisplayTextPrivate( )
                    set PRIVATE = false
                endif
            endmethod
        endstruct
    endscope
    private function ConvertText takes nothing returns nothing
        local string origString = GetEventPlayerChatString( )
        local string codeString = SubString( origString, 0, 3 )
        local integer end = StringLength( origString )
        local integer isAlly = 0
        call BJDebugMsg( "TTest" )
        set SENDPLAYER = GetTriggerPlayer( )
        if codeString == "-p " then
            set PRIVATE = true
            set WHOPRIVATE = S2I( SubString( origString, 3, 5 ) )
            set MESSAGE = SubString( origString, 3, end )
            return
        else
            set isAlly = isAlly + 1
        endif
        if codeString == "-al" then
            set ALL = true
            set MESSAGE = SubString ( origString, 3, end )
            return
        else
            set isAlly = isAlly + 1
        endif
        if isAlly == 2 then
            set ALLIES = true
        endif
        set MESSAGE = SubString( origString, 0, end )
        call Text.SendMessage( )
        set origString = null
        set codeString = null
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger( )
        local integer i = 0
        call BJDebugMsg( "Test" )
        call DoMapSetup( )
        loop
            if GetPlayerSlotState( Player( i ) ) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController( Player( i ) ) == MAP_CONTROL_USER then
                call TriggerRegisterPlayerEvent( t, Player( i ), EVENT_PLAYER_CHAT )
            endif
            set i = i + 1
            exitwhen i > bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddAction( t, function ConvertText )
        set t = null
    endfunction
endlibrary
 
Last edited:
Level 9
Joined
Apr 23, 2011
Messages
460
I've moved it to various other sections of the script but I'm unsure of if that is the underlying problem because I don't see any Debug Messages when placed in any part of the system that would be triggered by the any chat event o.o I don't understand.

Edit created its own function to be added to the trigger... It gives access violation fatal error. I'm starting to think about scrapping a large portion of this system and just starting that part over.
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,243
DoMapSetup is called before the event is registered. You are trying to add a player into a force that is null, that will cause problems and the event won't register since the code stops running. I'm sure of this, you can test it with debug mesages. Add another debug after the DoMapSetup call and you'll see.

Not sure about the reasons behind the crash.
 
Level 9
Joined
Apr 23, 2011
Messages
460
I found the reason for the crash! If you loop through ALL players to apply an object or assign something to them, it can cause an access violation, and therefore I fixed this by doing a loop through 11 instead of bj_MAX_PLAYER_SLOTS. I'm not certain why this is occurring, but I was working on another map, experiencing the same problem, and I change the bj_MAX_PLAYER_SLOTS to 11 and it caused the code to work properly. I'll begin reordering the code.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
It works, triggers when a player type any chat message.

Tested and i know why it is never used, the event will indeed fire, but GetEventPlayerChatString and GetEventPlayerChatStringMatched return null with it, so using this event is quite pointless, isnt it ?
TriggerRegisterPlayerChatEvent with a string "" and a false boolean argument is the way to go.

I found the reason for the crash! If you loop through ALL players to apply an object or assign something to them, it can cause an access violation, and therefore I fixed this by doing a loop through 11 instead of bj_MAX_PLAYER_SLOTS. I'm not certain why this is occurring, but I was working on another map, experiencing the same problem, and I change the bj_MAX_PLAYER_SLOTS to 11 and it caused the code to work properly. I'll begin reordering the code.

From blizzard.j :

JASS:
    constant integer   bj_MAX_PLAYER_SLOTS              =  16

Note, that there are 16 players and it starts from 0 to 15 included, Player(16) is not a valid player.
 
Level 9
Joined
Apr 23, 2011
Messages
460
Thank you for bringing that to light for me Troll-Brain, I had a feeling it was something of the sort. Anyways I believe I have corrected the error involving the force, if I am wrong, please tell me. The coding is getting farther but it is still not finishing, I continue now to dig into fixing these pesky errors.

EDIT: The script is registering the forms correctly, however not displaying. Looking into it now.
 
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
Your naming convention is quite horrible :
http://www.hiveworkshop.com/forums/...83/jpag-jass-proper-application-guide-204383/

Note that for variables (not constant ones), i personnaly use local_variable and Global_variable.

Again there is a crash because of an unitialized variable PLAYFORCE.
You must use CreateForce before using the force.

Plus, in the ConvertText function, depends the evaluation of the ifs, some variables may be still unitialized when Text.SendMessage() will be called.

Just give a default value to the variables in the global declaration.
Arrays are not concerned, they have the value "null" by default.
 
Level 9
Joined
Apr 23, 2011
Messages
460
The addition of CreateForce() when declared was very effective in solving a grand amount of issues. This is very good. Thank you. Slight changes will be made to the Private system to cause it to work correctly, other than that, It is working well! Thank you once again. I was unaware of the need to call CreateForce().
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Old gui adept i guess ?
Because the GUI variable editor creates it for you if i remember correctly (even if you don't want it btw).

In a general manner, all handles must be "created" before be "filled", like hashtable, force, group, unit/itempool...

Same for unitialized variables, with the GUI variable editor, no way that you got an unitialized variable. (but the defaults values are given in a really lame way)
 
Level 9
Joined
Apr 23, 2011
Messages
460
Yes, I've been teaching myself Jass and vJass for a while now. Well I also apologize for the naming and such, I wanted to "get it to work" before I even consider making the coding "look good". Once everything is done and fully tested and cleaned up, included proper naming convention, I will consider to post this system because I was looking for a vJass chat system and couldn't really find one (all were jass or didn't have the functions i wanted ) ;) so I decided to write my own. In the process of doing this I learned a lot about Substrings from you and DSG and various other members and I thank you all. I'll be sure to fix it all up soon. Thank you kindly for your volunteered time helping someone like me on scripting, along with your patience.

Edit: The blunt of the script is finished, some minor functions need to be added yet so that it has the functionality that I want ;). I thank everyone who has helped me with this script. Although it's probably not important to anyone else, I am sort of dedicating this system to someone who helped me write it out, a real friend of my who took his life this last Saturday, may he rest in peace. I felt that I had to finish this in honor of him. Thank you all for helping me finish this, and letting me fulfill this goal of mine.
 
Last edited:
Status
Not open for further replies.
Top