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

[JASS] Simple Chat System Problem

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
JASS:
scope AddChatMessage

globals
    multiboard array MB [11]
    integer MB_COUNTER = 0
    force ALL_PLAYERS = CreateForce()
    string TEMP_STRING
    boolean TEMP_BOOLEAN
    integer TEMP_INTEGER
    player TEMP_PLAYER
    string array MB_STRINGS [11][9]
    integer array MB_CHATSIZE [11]
endglobals

private function UpdateMultiboard takes nothing returns nothing
    local integer p = GetPlayerId(GetEnumPlayer())
    local integer a = 0
    
    if (IsPlayerAlly(Player(p), TEMP_PLAYER) == true) or (TEMP_BOOLEAN == true) or (Player(p) == TEMP_PLAYER) then
        loop
            call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a + 1])
            set MB_STRINGS[a] = MB_STRINGS[a + 1]
            set a = a + 1
            exitwhen a >= MB_CHATSIZE - 1
        endloop
        
        if Player(p) != TEMP_PLAYER then
            set MB_STRINGS[a] = "[|cffff9200" + GetPlayerName(TEMP_PLAYER) + "|r] " + TEMP_STRING
        elseif TEMP_BOOLEAN == true then
            set MB_STRINGS[a] = "[|cffff0000Allies|r]: " + TEMP_STRING
        else
            set MB_STRINGS[a] = "[|cff6464ffAllies|r]: " + TEMP_STRING
        endif
        
        call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a])
    endif
endfunction

private function Actions takes nothing returns nothing
    local string s = GetEventPlayerChatString()
    
    if SubString(s, 0, 1) == "+" then
        if SubString(s, 1, 2) == "+" then
            set TEMP_BOOLEAN = true
            set TEMP_STRING = SubString(s, 2, StringLength(s))
        else
            set TEMP_BOOLEAN = false
            set TEMP_STRING = SubString(s, 1, StringLength(s))
        endif
        
        set TEMP_PLAYER = GetTriggerPlayer()
        call ForForce(ALL_PLAYERS, function UpdateMultiboard)
    endif
    
    set s = null
endfunction

//===========================================================================
function InitTrig_AddChatMessage takes nothing returns nothing
    set gg_trg_AddChatMessage = CreateTrigger()
    
    call TriggerAddAction(gg_trg_AddChatMessage, function Actions)
endfunction

endscope

The problem is, whenever I type something with "++" in front of it, the next thing I type erases it.

I attached an image that shows the problem.
 

Attachments

  • Chat System.JPG
    Chat System.JPG
    12 KB · Views: 94
Last edited:
Try changing this
JASS:
loop
    set MB_STRINGS[a] = MB_STRINGS[a + 1]
    call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a])
    set a = a + 1
    exitwhen a >= MB_CHATSIZE - 1
endloop
To this
JASS:
loop
    exitwhen a >= MB_CHATSIZE - 1
    set MB_STRINGS[a] = MB_STRINGS[a + 1]
    call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a])
    set a = a + 1
endloop

And don't get so angry when people don't reply. It's a hard question to answer. I had to bump a thread 4 times once before I got a reply (over a course of over a week). I didn't get so angry...
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
Your code. Giving your variables better names would make this so much readable.

MB = Multiboards... Seems pretty simple and straightforward to me.
MB_STRINGS = Each line of chat on each multiboard. Given it's a 2D array, I think that would be easy to figure out.
MB_CHATSIZE = The maximum size each chatboard is (how many lines of chat it displays).

Does that clear things up?

Hopefully I don't have to explain the rest lol
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
It actually did clear a few things.

In any case, the only problem I could see is that MB_CHATSIZE[i] is never updated.
As in, when someone types a correct line (+...) MB_CHATSIZE[p] should be increased, and if a row goes out of the multiboard, it should be decreased.
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
MB_CHATSIZE is the maximum size of the chat, not the current number of lines typed.

Also I don't even have a way of altering it yet. That shouldn't be the problem. I've tested this in about 30 different ways and I think it's the wierdest bug *EVER* encountered. (not even the wierdest bug I have encountered, but that anyone has encountered)

try inserting

JASS:
call BJDebugMsg(MB_STRINGS[a])

Right after

JASS:
        call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a])

at the end of the
JASS:
UpdateMultiboard
function

The
JASS:
        call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRINGS[a])
displays a different value than what it says it is set to. Maybe newgen 2D arrays fail? I think I'll make my own 2D array and test.
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
JASS:
library TwoDimensionalArrays

function TwoDim takes integer x, integer y returns integer
    return x * 10 + y
endfunction

endlibrary

My own 2D array function

JASS:
scope AddChatMessage

globals
    multiboard array MB [11]
    force ALL_PLAYERS = CreateForce()
    string TEMP_STRING
    boolean TEMP_BOOLEAN
    integer TEMP_INTEGER
    player TEMP_PLAYER
    string array MB_STRINGS [11][9]
    string array MB_STRING
    integer array MB_CHATSIZE [11]
endglobals

private function UpdateMultiboard takes nothing returns nothing
    local integer p = GetPlayerId(GetEnumPlayer())
    local integer a = 0
    
    if IsPlayerAlly(Player(p), TEMP_PLAYER) or TEMP_BOOLEAN or Player(p) == TEMP_PLAYER then
        loop
            set MB_STRING[TwoDim(p, a)] = MB_STRING[TwoDim(p, a + 1)]
            call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRING[TwoDim(p, a)])
            set a = a + 1
            exitwhen a >= MB_CHATSIZE - 1
        endloop
        
        if Player(p) != TEMP_PLAYER then
            set MB_STRING[TwoDim(p, a)] = "[" + GetPlayerNameColored(TEMP_PLAYER) + "] " + TEMP_STRING
        elseif TEMP_BOOLEAN then
            set MB_STRING[TwoDim(p, a)] = "[|cffff0000All|r]: " + TEMP_STRING
        else
            set MB_STRING[TwoDim(p, a)] = "[|cff6464ffAllies|r]: " + TEMP_STRING
        endif
        
        call MultiboardSetItemValue(MultiboardGetItem(MB, a, 0), MB_STRING[TwoDim(p, a)])
        call BJDebugMsg(MB_STRING[TwoDim(p, a)])
    endif
endfunction

private function Actions takes nothing returns nothing
    local string s = GetEventPlayerChatString()
    
    if SubString(s, 0, 1) == "+" then
        if SubString(s, 1, 2) == "+" then
            set TEMP_BOOLEAN = true
            set TEMP_STRING = SubString(s, 2, StringLength(s))
        else
            set TEMP_BOOLEAN = false
            set TEMP_STRING = SubString(s, 1, StringLength(s))
        endif
        
        set TEMP_PLAYER = GetTriggerPlayer()
        call ForForce(ALL_PLAYERS, function UpdateMultiboard)
    endif
    
    set s = null
endfunction

//===========================================================================
function InitTrig_AddChatMessage takes nothing returns nothing
    set gg_trg_AddChatMessage = CreateTrigger()
    
    call TriggerAddAction(gg_trg_AddChatMessage, function Actions)
endfunction

endscope

IT WORKS!!! Except the BJDebugMsg is displaying the opposite still. But it's working :p
 
Status
Not open for further replies.
Top