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

[JASS] Not working (Divide a sentence - Commands)

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
function DiplomacyMain takes nothing returns boolean
    local string s = GetEventPlayerChatString()
    local integer curWord = 1
    local string word1 = ""
    local string word2 = ""
    local string word3 = ""
    local string word4 = ""
    local player p1 = GetTriggerPlayer()
    local player p2 
    local integer i = 2

    call DisplayTextToForce( GetPlayersAll(), "Working this far..." )

    loop
        exitwhen i > StringLength(s)
        if (SubStringBJ(s,i,i) == " ") then
            set curWord = curWord + 1
        else 
            if (curWord == 1) then 
                set word1 = word1 + SubStringBJ(s, i, i)
            elseif (curWord == 2) then
                set word2 = word2 + SubStringBJ(s, i, i)
            elseif (curWord == 3) then
                set word3 = word3 + SubStringBJ(s, i, i)
            elseif (curWord == 4) then
                 set word4 = word4 + SubStringBJ(s, i, i)
            endif
        endif     
        set i = i + 1
    endloop

    set p2 = Player(PlayerCommand(word2))

    call DisplayTextToForce( GetPlayersAll(), "Word 1: " + word1 )
    call DisplayTextToForce( GetPlayersAll(), "Word 2: " + word2 )
    call DisplayTextToForce( GetPlayersAll(), "Word 3: " + word3 )
    call DisplayTextToForce( GetPlayersAll(), "Word 4: " + word4 )

    set p1 = null
    set p2 = null
    return false
endfunction


//===========================================================================
function InitTrig_Diplomacy_Commands takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(1), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(2), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(3), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(4), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(5), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(6), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(7), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(8), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(9), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(10), "-", false )
    call TriggerRegisterPlayerChatEvent( t, Player(11), "-", false )
    call TriggerAddCondition( t, Condition( function DiplomacyMain) )
    set t = null
endfunction

Tried to make a trigger that retrieves 4 words from the entered string.

It works til the first word, when i try "-hi" but if i type "-hi ho" it crashes.

Oh I know what it was.... I think Player("ho") makes it crash xD
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Players out side the range 0 to 15 cause the game to crash. I am not sure if this is because Player returns null which causes the game to crash when resolved in other functions or if the Player function itself crashes the game.

At least in SC2 you get a nice error message and the game does not crash.
 
Status
Not open for further replies.
Top