• 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.

[JASS] Multiboard Help

Status
Not open for further replies.
Level 4
Joined
Oct 2, 2011
Messages
89
I am working on code to have multiboard display various text messages to user. I have decided to try JASS for this and managed to set up everything. Basically the text is set to wrap around the limits of the multiboard. I got the numbers off of taking screenshots of in game and measuring the character width.
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,20)
    call MultiboardSetTitleText(udg_dia,"Output") 
    call MultiboardDisplay(udg_dia,true)  
endfunction

function calclen takes string input, integer startchar returns integer
    local integer max = 327
    local integer len = StringLength(input)
    local integer lencount = 0
    local integer endchar = startchar
    local boolean done = false 
    loop
        set endchar = startchar + 1
        if lencount <= max or endchar == len then
            //Part I parse string
            if SubString(input,endchar,endchar) == "a" or SubString(input,endchar,endchar) == "b" or SubString(input,endchar,endchar) == "c" or SubString(input,endchar,endchar) == "d" or SubString(input,endchar,endchar) == "e" or SubString(input,endchar,endchar) == "h" or SubString(input,endchar,endchar) == "n" or SubString(input,endchar,endchar) == "u" or SubString(input,endchar,endchar) == "k" or SubString(input,endchar,endchar) == "z" then
                set lencount = lencount + 8
                elseif SubString(input,endchar,endchar) == "2" or SubString(input,endchar,endchar) == "4" or SubString(input,endchar,endchar) == "6" or SubString(input,endchar,endchar) == "8" or SubString(input,endchar,endchar) == "9" or SubString(input,endchar,endchar) == "0" or SubString(input,endchar,endchar) == "g" or SubString(input,endchar,endchar) == "o" or SubString(input,endchar,endchar) == "p" or SubString(input,endchar,endchar) == "q" or SubString(input,endchar,endchar) == "v" or SubString(input,endchar,endchar) == "x" or SubString(input,endchar,endchar) == "y" then
                    set lencount = lencount + 9
                    elseif SubString(input,endchar,endchar) == "1" or SubString(input,endchar,endchar) == "f" or SubString(input,endchar,endchar) == "r" then
                        set lencount = lencount + 5
                        elseif SubString(input,endchar,endchar) == "i" or SubString(input,endchar,endchar) == " " or SubString(input,endchar,endchar) == "j" or SubString(input,endchar,endchar) == "l" or SubString(input,endchar,endchar) == "(" or SubString(input,endchar,endchar) == ")" then
                            set lencount = lencount + 4
                            elseif SubString(input,endchar,endchar) == "3" or SubString(input,endchar,endchar) == "5" or SubString(input,endchar,endchar) == "7" or SubString(input,endchar,endchar) == ">" or SubString(input,endchar,endchar) == "<" then
                                set lencount = lencount + 7
                                elseif SubString(input,endchar,endchar) == "m" or SubString(input,endchar,endchar) == "w" then
                                    set lencount = lencount + 13
                                    elseif SubString(input,endchar,endchar) == "." or SubString(input,endchar,endchar) == "," then
                                        set lencount = lencount + 3
                                        elseif SubString(input,endchar,endchar) == "*" then
                                            set lencount = lencount + 6
            endif
        else
           set done = true
        endif
        exitwhen  done == true
    endloop
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 0
    local integer endchar = 0
    local integer a = 1
    local integer len = StringLength(input)
    call MultiboardClear(udg_dia)
    call MultiboardSetRowCount(a)
    loop
        set endchar = calclen(input,startchar)
        call MultiboardSetRowCount(udg_dia,a)
        call MultiboardSetItemValue(MultiboardGetItem(udg_dia,a,1),SubString(input,startchar,endchar))
        set a = a + 1    
        exitwhen endchar == len
    endloop   
endfunction

that is the code to have everything work, and I made some triggers to test/debug the system.
  • Untitled Trigger 004
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Custom script: call multiboardinit()
That one starts the multiboard, and it works well, but this one does not...
  • MultiTest
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Custom script: call writetoboard(GetEventPlayerChatString())
I know the trigger is not done yet (I am going to have better word wrap with new lines on spaces and reorder the if statements so more commonly used letters are first), but the writetoboard function does not seem to work as well as I want. Whenever I type in game "-[whatever]" no text is displayed :ogre_frown:, and the multiboard shrinks to a smaller size than .2. I don't know why this would not work, and even if it didn't work, I have no idea why the multiboard shrinks.
 
Last edited:
change this
JASS:
call MultiboardSetItemsWidth(udg_dia,20)
to this
JASS:
call MultiboardSetItemsWidth(udg_dia, .02)

and do not use multiboardClear
instead create a local variable multiboarditem and use this to change the item values in the multiboard

you should also think about using the proper naming method for functions and the proper indentation for easier reading.

function names are like this
JASS:
function WriteToBoard

indentation is like this
JASS:
function Ites
    if .... then
        set ....
    elseif .... then
        set ....
    endif
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
call MultiboardSetItemsWidth(udg_dia,20)
I think you are trying to set the width to what GUI would call "2000%". The GUI wrappers divide the given value by 100.0 before passing it to the natives.

call MultiboardSetItemValue(MultiboardGetItem(udg_dia,a,1),SubString(input,startchar,endchar))
You never release the multiboard item. I do not think any changes are made until the item is released and in any case it should probably be classed as a leak.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
How do I "release" a multiboard?
You do not want to do that. You want to release the multiboarditem you make.
JASS:
native MultiboardReleaseItem takes multiboarditem mbi returns nothing

One of the BJ functions GUI uses shows it being used.
JASS:
function MultiboardSetItemValueBJ takes multiboard mb,integer col,integer row,string val returns nothing
    local integer curRow = 0
    local integer curCol = 0
    local integer numRows = MultiboardGetRowCount(mb)
    local integer numCols = MultiboardGetColumnCount(mb)
    local multiboarditem mbitem = null
    loop
        set curRow = curRow + 1
        exitwhen curRow > numRows
        if (row == 0 or row == curRow) then
            set curCol = 0
            loop
                set curCol = curCol + 1
                exitwhen curCol > numCols
                if (col == 0 or col == curCol) then
                    set mbitem = MultiboardGetItem(mb, curRow - 1, curCol - 1)
                    call MultiboardSetItemValue(mbitem, val)
                    call MultiboardReleaseItem(mbitem)
                endif
            endloop
        endif
    endloop
endfunction
Although I really think they should be nulling mbitem at the end of the function.

This also reveals another bug in your code. Columns and rows start from 0 not 1 (as the BJ shows, GUI adds an offset to emulate it starting from 1). You are trying to set the value of a row and column that do not exist.

To better demonstrate this, here is an example. Say we make a multiboard with 2 rows and 2 columns. The following list is of valid multiboarditem positions.
0,0 (what GUI would call 1,1)
0,1 (what GUI would call 1,2)
1,1 (what GUI would call 2,2)
1,0 (what GUI would call 2,1)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
for some reason they null it in the local variable at the top. i think this is one of the reasons y multiboards always leak in gui because they dont null it at the end
The programmers who wrote the BJ functions for GUI were not aware that WarCraft III had a reference counter bug with local variables. Many BJ functions leak.
 
Level 4
Joined
Oct 2, 2011
Messages
89
I changed code to
JASS:
function writetoboard takes string input returns nothing
    local integer startchar = 0
    local integer endchar = 0
    local integer a = 1
    local integer len = StringLength(input)
    call MultiboardClear(udg_dia)
    call MultiboardSetRowCount(udg_dia,a)
    loop
        set endchar = calclen(input,startchar)
        call MultiboardSetRowCount(udg_dia,a)
        call MultiboardSetItemsWidth(udg_dia,.20)
        call MultiboardSetItemValue(MultiboardGetItem(udg_dia,a,1),SubString(input,startchar,endchar))
        call MultiboardReleaseItem(MultiboardGetItem(udg_dia,a,1))
        set a = a + 1
        set startchar = endchar
        exitwhen endchar == len
    endloop
endfunction
The board is the right size now, but still the text is not displayed at all

EDIT: changed a to 0 and the code in MultiboardGetItem() to 0 and it still does not work...
 
The programmers who wrote the BJ functions for GUI were not aware that WarCraft III had a reference counter bug with local variables. Many BJ functions leak.

ooo ok i didnt know this lol thx for clearing that up.

you should not need to keep resetting the row count and other stuff just set that once in the init function u have up top
 
Level 4
Joined
Oct 2, 2011
Messages
89
When a new message comes up, I want the old message to go away. Thus, I am going to reset the rows every time a new message comes up because some messages will not use as many rows as others....
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You have remembered to allow text in those cells?
JASS:
native MultiboardSetItemStyle takes multiboarditem mbi,boolean showValue,boolean showIcon returns nothing
Specifically, showValue must be true. Maybe that information is lost during resizing so the global one you run earlier is lost.
 
Level 4
Joined
Oct 2, 2011
Messages
89
yes it is in init function.
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,20)
    call MultiboardSetTitleText(udg_dia,"Output") 
    call MultiboardDisplay(udg_dia,true)  
endfunction
 
Level 4
Joined
Oct 2, 2011
Messages
89
I have updated many things about the code, but still no improvement. No text shows up...
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,.20)
    call MultiboardSetTitleText(udg_dia,"Multiboard")
    call MultiboardDisplay(udg_dia,true)  
endfunction

function calclen takes string input, integer startchar returns integer
    local integer max = 327
    local integer len = StringLength(input)
    local integer lencount = 0
    local integer endchar = startchar
    local boolean done = false 
    loop
        if lencount <= max or endchar == len then
            //Part I parse string
            if SubString(input,endchar,endchar) == "a" or SubString(input,endchar,endchar) == "b" or SubString(input,endchar,endchar) == "c" or SubString(input,endchar,endchar) == "d" or SubString(input,endchar,endchar) == "e" or SubString(input,endchar,endchar) == "h" or SubString(input,endchar,endchar) == "n" or SubString(input,endchar,endchar) == "u" or SubString(input,endchar,endchar) == "k" or SubString(input,endchar,endchar) == "z" then
                set lencount = lencount + 8
                elseif SubString(input,endchar,endchar) == "2" or SubString(input,endchar,endchar) == "4" or SubString(input,endchar,endchar) == "6" or SubString(input,endchar,endchar) == "8" or SubString(input,endchar,endchar) == "9" or SubString(input,endchar,endchar) == "0" or SubString(input,endchar,endchar) == "g" or SubString(input,endchar,endchar) == "o" or SubString(input,endchar,endchar) == "p" or SubString(input,endchar,endchar) == "q" or SubString(input,endchar,endchar) == "v" or SubString(input,endchar,endchar) == "x" or SubString(input,endchar,endchar) == "y" then
                    set lencount = lencount + 9
                    elseif SubString(input,endchar,endchar) == "1" or SubString(input,endchar,endchar) == "f" or SubString(input,endchar,endchar) == "r" then
                        set lencount = lencount + 5
                        elseif SubString(input,endchar,endchar) == "i" or SubString(input,endchar,endchar) == " " or SubString(input,endchar,endchar) == "j" or SubString(input,endchar,endchar) == "l" or SubString(input,endchar,endchar) == "(" or SubString(input,endchar,endchar) == ")" then
                            set lencount = lencount + 4
                            elseif SubString(input,endchar,endchar) == "3" or SubString(input,endchar,endchar) == "5" or SubString(input,endchar,endchar) == "7" or SubString(input,endchar,endchar) == ">" or SubString(input,endchar,endchar) == "<" then
                                set lencount = lencount + 7
                                elseif SubString(input,endchar,endchar) == "m" or SubString(input,endchar,endchar) == "w" then
                                    set lencount = lencount + 13
                                    elseif SubString(input,endchar,endchar) == "." or SubString(input,endchar,endchar) == "," then
                                        set lencount = lencount + 3
                                        elseif SubString(input,endchar,endchar) == "*" then
                                            set lencount = lencount + 6
            endif
        else
           set done = true
        endif
        set endchar = endchar + 1
        exitwhen  done == true
    endloop
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 0
    local integer endchar = 0
    local integer a = 0
    local integer len = StringLength(input)
    local multiboarditem mbitem
    local integer b = 0
    loop
        set mbitem = MultiboardGetItem(udg_dia,b,0)
        call MultiboardSetItemValue(mbitem,"")
        set b = b + 1
        exitwhen b == MultiboardGetRowCount(udg_dia)
    endloop
    loop
        set endchar = calclen(input,startchar)
        call MultiboardSetRowCount(udg_dia,a + 1)
        call MultiboardSetItemsWidth(udg_dia,.20)
        set mbitem = MultiboardGetItem(udg_dia,a,0)
        call MultiboardSetItemsStyle(udg_dia,true,false)
        call MultiboardSetItemValue(mbitem,SubString(input,startchar,endchar))
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
        set a = a + 1
        set startchar = endchar
        exitwhen endchar == len
    endloop
endfunction
 
Level 4
Joined
Oct 2, 2011
Messages
89
I found something very unusual...
deathismyfriend even though I think you were wrong about substring, you gave me an idea, to print values to screen to see if that is the problem. I fixed a bunch of the code so now it is full JASS (I am learning as I go I guess...) but even with the displayed message, nothing is displayed. This makes me think something is wrong with my calclen function...
Here is new code:
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,.20)
    call MultiboardSetTitleText(udg_dia,"Multiboard")
    call MultiboardDisplay(udg_dia,true)  
endfunction

function calclen takes string input, integer startchar returns integer
    local integer max = 327
    local integer len = StringLength(input)
    local integer lencount = 0
    local integer endchar = startchar
    local boolean done = false 
    loop
        if lencount <= max or endchar == len then
            //Part I parse string
            if SubString(input,endchar,endchar) == "a" or SubString(input,endchar,endchar) == "b" or SubString(input,endchar,endchar) == "c" or SubString(input,endchar,endchar) == "d" or SubString(input,endchar,endchar) == "e" or SubString(input,endchar,endchar) == "h" or SubString(input,endchar,endchar) == "n" or SubString(input,endchar,endchar) == "u" or SubString(input,endchar,endchar) == "k" or SubString(input,endchar,endchar) == "z" then
                set lencount = lencount + 8
                elseif SubString(input,endchar,endchar) == "2" or SubString(input,endchar,endchar) == "4" or SubString(input,endchar,endchar) == "6" or SubString(input,endchar,endchar) == "8" or SubString(input,endchar,endchar) == "9" or SubString(input,endchar,endchar) == "0" or SubString(input,endchar,endchar) == "g" or SubString(input,endchar,endchar) == "o" or SubString(input,endchar,endchar) == "p" or SubString(input,endchar,endchar) == "q" or SubString(input,endchar,endchar) == "v" or SubString(input,endchar,endchar) == "x" or SubString(input,endchar,endchar) == "y" then
                    set lencount = lencount + 9
                    elseif SubString(input,endchar,endchar) == "1" or SubString(input,endchar,endchar) == "f" or SubString(input,endchar,endchar) == "r" then
                        set lencount = lencount + 5
                        elseif SubString(input,endchar,endchar) == "i" or SubString(input,endchar,endchar) == " " or SubString(input,endchar,endchar) == "j" or SubString(input,endchar,endchar) == "l" or SubString(input,endchar,endchar) == "(" or SubString(input,endchar,endchar) == ")" then
                            set lencount = lencount + 4
                            elseif SubString(input,endchar,endchar) == "3" or SubString(input,endchar,endchar) == "5" or SubString(input,endchar,endchar) == "7" or SubString(input,endchar,endchar) == ">" or SubString(input,endchar,endchar) == "<" then
                                set lencount = lencount + 7
                                elseif SubString(input,endchar,endchar) == "m" or SubString(input,endchar,endchar) == "w" then
                                    set lencount = lencount + 13
                                    elseif SubString(input,endchar,endchar) == "." or SubString(input,endchar,endchar) == "," then
                                        set lencount = lencount + 3
                                        elseif SubString(input,endchar,endchar) == "*" then
                                            set lencount = lencount + 6
            endif
            set endchar = endchar + 1
            set lencount = lencount + 1
        else
           set done = true
        endif
        exitwhen  done == true
    endloop
    /*
    Below for Test only...
    */
    call DisplayTextToForce(GetPlayersAll(),I2S(startchar)) 
    call DisplayTextToForce(GetPlayersAll(),I2S(endchar))  
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 0
    local integer endchar = 0
    local integer a = 0
    local integer len = StringLength(input)
    local multiboarditem mbitem
    local integer b = 0
    loop
        set mbitem = MultiboardGetItem(udg_dia,b,0)
        call MultiboardSetItemValue(mbitem,"")
        set b = b + 1
        exitwhen b == MultiboardGetRowCount(udg_dia)
    endloop
    loop
        set endchar = calclen(input,startchar)
        call MultiboardSetRowCount(udg_dia,a + 1)
        call MultiboardSetItemsWidth(udg_dia,.20)
        set mbitem = MultiboardGetItem(udg_dia,a,0)
        call MultiboardSetItemsStyle(udg_dia,true,false)
        call MultiboardSetItemValue(mbitem,SubString(input,startchar,endchar))
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
        set a = a + 1
        set startchar = endchar
        exitwhen endchar == len
    endloop
endfunction

function display takes nothing returns nothing
    call writetoboard(GetEventPlayerChatString())
endfunction

function InitTrig_multiboard takes nothing returns nothing
    local trigger init = CreateTrigger()
    local trigger callevent = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( callevent, Player(0), "-", true )
    call TriggerAddAction(callevent,function display)
    call TriggerRegisterTimerEventSingle(init,5)
    call TriggerAddAction(init, function multiboardinit)
endfunction

Look at the part:
JASS:
     /*
    Below for Test only...
    */
    call DisplayTextToForce(GetPlayersAll(),I2S(startchar)) 
    call DisplayTextToForce(GetPlayersAll(),I2S(endchar))
Even though that is there nothing happens... :ogre_frown: Could the game be stuck in an infinite loop?
 
Level 4
Joined
Oct 2, 2011
Messages
89
I am making this system for my map. Right now I am building the system in test map (less lag in editor, quick testing time, etc.) Here is the test map:
(Just ignore the other trigger in the map, it is for another system I am doing...)
 

Attachments

  • dia.w3x
    11.2 KB · Views: 40
I am making this system for my map. Right now I am building the system in test map (less lag in editor, quick testing time, etc.) Here is the test map:
(Just ignore the other trigger in the map, it is for another system I am doing...)

ok lol i do the same

it partially works it doesnt wrap the lines but it does post the message on the mb
heres the map ill continue to try. also i cleaned up some leaks and got rid of some of the bjs that u used
 

Attachments

  • dia.w3x
    11.2 KB · Views: 47
Last edited:
there is still a big problem the calclen function is messing up. the main problem is the substring it keeps returning null value.

i changed this
JASS:
    call TriggerRegisterPlayerChatEvent( callevent, Player(0), "-", false )

and a few other minor things although i forget the others lol
dont forget always null local variable at the end of functions
 
yeah I think I have found the problem with calclen and I am working on it atm. When you say null all local vars, does that include integers and triggers?

sry i shouldve said null all local handle variables.

integers reals booleans dont need to be nulled everything else does.

look for the comment that is the problem
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,.20)
    call MultiboardSetTitleText(udg_dia,"Multiboard")
    call MultiboardDisplay(udg_dia,true)  
endfunction

function calclen takes string input, integer startchar returns integer
    local integer max = 327
    local integer len = StringLength(input)
    local integer lencount = 0
    local integer endchar = startchar
    local boolean done = false
    local string sub
    call BJDebugMsg( input)
    call BJDebugMsg( SubString(input,endchar,endchar)) // see this returns null 
    loop
        set sub = SubString(input,endchar,endchar)
        if lencount <= max or endchar == len or endchar == null then
            //Part I parse string
            //call BJDebugMsg( sub)
            if sub == "a" or sub == "b" or sub == "c" or sub == "d" or sub == "e" or sub == "h" or sub == "n" or sub == "u" or sub == "k" or sub == "z" then
                set lencount = lencount + 8
                call CreateUnit( Player(0), 'hpea', 0, 0, 0)
            elseif sub == "2" or sub == "4" or sub == "6" or sub == "8" or sub == "9" or sub == "0" or sub == "g" or sub == "o" or sub == "p" or sub == "q" or sub == "v" or sub == "x" or sub == "y" then
                set lencount = lencount + 9
            elseif sub == "1" or sub == "f" or sub == "r" then
                set lencount = lencount + 5
            elseif sub == "i" or sub == " " or sub == "j" or sub == "l" or sub == "(" or sub == ")" then
                set lencount = lencount + 4
            elseif sub == "3" or sub == "5" or sub == "7" or sub == ">" or sub == "<" then
                set lencount = lencount + 7
            elseif sub == "m" or sub == "w" then
                set lencount = lencount + 13
            elseif sub == "." or sub == "," then
                set lencount = lencount + 3
            elseif sub == "*" then
                set lencount = lencount + 6
            endif
        else
           set done = true
        endif
        set endchar = endchar + 1
        set lencount = lencount + 1
        exitwhen done == true
    endloop
    /*
    Below for Test only...
    */
    call DisplayTextToForce(GetPlayersAll(),I2S(startchar)) 
    call DisplayTextToForce(GetPlayersAll(),I2S(endchar))
    set sub = null
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 0
    local integer endchar = 0
    local integer a = 0
    local integer len = StringLength(input)
    local multiboarditem mbitem
    local integer b = 0
    loop
        set mbitem = MultiboardGetItem(udg_dia,b,0)
        call MultiboardSetItemValue(mbitem,"")
        set b = b + 1
        exitwhen b == MultiboardGetRowCount(udg_dia)
    endloop
    call BJDebugMsg( input)
    loop
        set endchar = calclen(input,startchar)
        call MultiboardSetRowCount(udg_dia,a + 1)
        call MultiboardSetItemsWidth(udg_dia,.20)
        set mbitem = MultiboardGetItem(udg_dia,a,0)
        call MultiboardSetItemsStyle(udg_dia,true,false)
        call MultiboardSetItemValue(mbitem,SubString(input,startchar,endchar))
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
        set a = a + 1
        set startchar = endchar
        exitwhen endchar == len
    endloop
endfunction

function display takes nothing returns nothing
    local string sub = GetEventPlayerChatString()
    set sub = SubString(GetEventPlayerChatString(),1,StringLength(sub))
    call writetoboard(sub)
    set sub = null
endfunction

function InitTrig_multiboard takes nothing returns nothing
    local trigger init = CreateTrigger()
    local trigger callevent = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( callevent, Player(0), "-", false )
    call TriggerAddAction(callevent,function display)
    call TriggerRegisterTimerEvent( init, 0.00, false)
    call TriggerAddAction(init, function multiboardinit)
    set init = null
    set callevent = null
endfunction

the only way i can think of fixing it is by changing the functions. it would involve quite a bit of reworking to the 2 main functions in there calclen and writetoboard
 
Level 4
Joined
Oct 2, 2011
Messages
89
I think I have found a different way to solve the problem.
I made new map with updated code that now works... kind of.
I made a message to display where every time calclen runs, it shows the current width count. This works and the messages are shown but the text is not added to the next line and the multiboard does not resize. This makes me think calclen is fixed, but now the loop in writetoboard is the problem.
Here is Code:
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,.20)
    call MultiboardSetTitleText(udg_dia,"Multiboard")
    call MultiboardDisplay(udg_dia,true)  
endfunction

function StringSub takes string source, integer start, integer end returns string
    return SubString(source, start-1, end)
endfunction

function clearboard takes nothing returns nothing
    local multiboarditem mbitem
    local integer b = 0
    loop
        set mbitem = MultiboardGetItem(udg_dia,b,0)
        call MultiboardSetItemValue(mbitem,"")
        set b = b + 1
        exitwhen b == MultiboardGetRowCount(udg_dia)
    endloop
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetItemsWidth(udg_dia,.20)
    set mbitem = null
endfunction

function calclen takes string input, integer startchar returns integer
    local integer maxpix = 327
    local integer maxlen = StringLength(input)
    local integer curpix = 0
    local integer endchar = startchar - 1
    local boolean done = false
    local string sub 
    loop
        set sub = StringSub(input,endchar,endchar)
        if curpix <= maxpix and endchar < maxlen then
            if sub == "a" or sub == "b" or sub == "c" or sub == "d" or sub == "e" or sub == "h" or sub == "n" or sub == "u" or sub == "k" or sub == "z" then
                set curpix = curpix + 8
            elseif sub == "2" or sub == "4" or sub == "6" or sub == "8" or sub == "9" or sub == "0" or sub == "g" or sub == "o" or sub == "p" or sub == "q" or sub == "v" or sub == "x" or sub == "y" then
                set curpix = curpix + 9
            elseif sub == "1" or sub == "f" or sub == "r" then
                set curpix = curpix + 5
            elseif sub == "i" or sub == " " or sub == "j" or sub == "l" or sub == "(" or sub == ")" then
                set curpix = curpix + 4
            elseif sub == "3" or sub == "5" or sub == "7" or sub == ">" or sub == "<" then
                set curpix = curpix + 7
            elseif sub == "m" or sub == "w" then
                set curpix = curpix + 13
            elseif sub == "." or sub == "," then
                set curpix = curpix + 3
            elseif sub == "*" then
                set curpix = curpix + 6
            endif
            set endchar = endchar + 1
        else
           set done = true
        endif
        exitwhen done == true
    endloop
    call DisplayTextToForce(GetPlayersAll(),I2S(curpix))
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 1
    local integer endchar
    local integer a = 0
    local integer len = StringLength(input)
    local multiboarditem mbitem
    call clearboard()
    loop
        set endchar = calclen(input,startchar)
        set mbitem = MultiboardGetItem(udg_dia,a,0)
        call MultiboardSetItemValue(mbitem,StringSub(input,startchar,endchar))
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
        exitwhen endchar == len
        set a = a + 1
        call MultiboardSetRowCount(udg_dia,a)
        call MultiboardSetItemsWidth(udg_dia,.20)
        set startchar = endchar + 1
    endloop
endfunction

function display takes nothing returns nothing
    local string sub = GetEventPlayerChatString()
    set sub = StringSub(GetEventPlayerChatString(),2,StringLength(sub))
    call writetoboard(sub)
    set sub = null
endfunction

function InitTrig_multiboard takes nothing returns nothing
    local trigger init = CreateTrigger()
    local trigger callevent = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( callevent, Player(0), "-", false )
    call TriggerAddAction(callevent,function display)
    call TriggerRegisterTimerEvent( init, 0.00, false)
    call TriggerAddAction(init, function multiboardinit)
    set init = null
    set callevent = null
endfunction
 
Level 4
Joined
Oct 2, 2011
Messages
89
Aha! I think I have made new discovery. I have got it to work where it displays text on the line, but only if the line is full..... in other words the last segment that is not actually a full line is ignored.... now time to figure out how to fix that...
 
Level 4
Joined
Oct 2, 2011
Messages
89
Well this is not good but... I continued messing with map to get it to work and now I have worse problem... The end piece and the second line are cut off (second line is just empty) :ogre_frown: I think I know the exact area of code there is a problem though, the for loop in writetoboard seems to be causing the trouble.

Edit: well this is pretty funny.... I now have fixed code so that the end part is not left out :D, but the second line now doesn't show. I've successfully fixed one bug and made another D:

Paste updated code in below map to see better working version
JASS:
function multiboardinit takes nothing returns nothing
    set udg_dia = CreateMultiboard()
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetColumnCount(udg_dia,1)
    call MultiboardSetItemsStyle(udg_dia,true,false)
    call MultiboardSetItemsWidth(udg_dia,.20)
    call MultiboardSetTitleText(udg_dia,"Multiboard")
    call MultiboardDisplay(udg_dia,true)  
endfunction

function StringSub takes string source, integer start, integer end returns string
    return SubString(source, start-1, end)
endfunction

function clearboard takes nothing returns nothing
    local multiboarditem mbitem
    local integer b = 0
    loop
        set mbitem = MultiboardGetItem(udg_dia,b,0)
        call MultiboardSetItemValue(mbitem,"")
        set b = b + 1
        exitwhen b == MultiboardGetRowCount(udg_dia)
    endloop
    call MultiboardSetRowCount(udg_dia,1)
    call MultiboardSetItemsWidth(udg_dia,.20)
    set mbitem = null
endfunction

function calclen takes string input, integer startchar returns integer
    local integer maxpix = 327
    local integer maxlen = StringLength(input)
    local integer curpix = 0
    local integer endchar = startchar - 1
    local boolean done = false
    local string sub 
    loop
        set sub = StringSub(input,endchar,endchar)
        if curpix <= maxpix and endchar < maxlen then
            if sub == "a" or sub == "b" or sub == "c" or sub == "d" or sub == "e" or sub == "h" or sub == "n" or sub == "u" or sub == "k" or sub == "z" then
                set curpix = curpix + 8
            elseif sub == "2" or sub == "4" or sub == "6" or sub == "8" or sub == "9" or sub == "0" or sub == "g" or sub == "o" or sub == "p" or sub == "q" or sub == "v" or sub == "x" or sub == "y" then
                set curpix = curpix + 9
            elseif sub == "1" or sub == "f" or sub == "r" then
                set curpix = curpix + 5
            elseif sub == "i" or sub == " " or sub == "j" or sub == "l" or sub == "(" or sub == ")" then
                set curpix = curpix + 4
            elseif sub == "3" or sub == "5" or sub == "7" or sub == ">" or sub == "<" then
                set curpix = curpix + 7
            elseif sub == "m" or sub == "w" then
                set curpix = curpix + 13
            elseif sub == "." or sub == "," then
                set curpix = curpix + 3
            elseif sub == "*" then
                set curpix = curpix + 6
            endif
            set endchar = endchar + 1
        else
           set done = true
        endif
        exitwhen done == true
    endloop
    call DisplayTextToForce(GetPlayersAll(),I2S(curpix))
    return endchar
endfunction

function writetoboard takes string input returns nothing
    local integer startchar = 1
    local integer endchar
    local integer a = 0
    local integer len = StringLength(input)
    local multiboarditem mbitem
    call clearboard()
    loop
        set endchar = calclen(input,startchar)
        set mbitem = MultiboardGetItem(udg_dia,a,0)
        call MultiboardSetItemValue(mbitem,StringSub(input,startchar,endchar))
        call MultiboardReleaseItem(mbitem)
        exitwhen endchar == len
        set a = a + 1
        call MultiboardSetRowCount(udg_dia,a + 1)
        set startchar = endchar + 1
    endloop
    set mbitem = null
endfunction

function display takes nothing returns nothing
    local string sub = GetEventPlayerChatString()
    set sub = StringSub(GetEventPlayerChatString(),2,StringLength(sub))
    call writetoboard(sub)
    set sub = null
endfunction

function InitTrig_multiboard takes nothing returns nothing
    local trigger init = CreateTrigger()
    local trigger callevent = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( callevent, Player(0), "-", false )
    call TriggerAddAction(callevent,function display)
    call TriggerRegisterTimerEvent( init, 0.00, false)
    call TriggerAddAction(init, function multiboardinit)
    set init = null
    set callevent = null
endfunction
 

Attachments

  • dia (1).w3x
    10.9 KB · Views: 35
Level 4
Joined
Oct 2, 2011
Messages
89
wow... Thank you very much, this works perfectly. You say I need to change values for wrapping? What is your screen resolution? It seems to work for me fine, but I based it off of my computer.
 
Status
Not open for further replies.
Top