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

Array sorting for my multiboard don't work

Status
Not open for further replies.
Level 9
Joined
Oct 28, 2007
Messages
435
Hey please help me. This is my code which sorts my mutliboard and it doesn't work. If you know of a more optimal way of sorting the array please tell me:

JASS:
function UpdateBoard takes nothing returns nothing
//PART 1
local integer array P[8] // List of Player Positions in Score Array// Index==Pos in Array value==player
local integer l=0//Loop
local integer l2=0 //
local integer i1//swap int 1
local integer i2//swap int 2

//PART 2
local multiboarditem i 

local integer p // The current player
local integer t //team of current player

local integer kr=0
local integer dr=0
local integer kb=0
local integer db=0



//=====================================================================================
//PART 1 Sorting P array
//=====================================================================================

loop
if GetPlayerSlotState(Player(l2))==PLAYER_SLOT_STATE_PLAYING then
set P[l]=l2
set l=l+1
endif
set l2=l2+1
exitwhen l==PLAYER_COUNT or l2==8
endloop

set l=0
loop
if score[P[l]]<score[P[l+1]] then
set i1=P[l]
set P[l]=P[l+1]
set P[l+1]=i1
set l=0
else
set l=l+1
endif
exitwhen l==PLAYER_COUNT
endloop



//=====================================================================================
//PART 2 Updating Multiboard
//=====================================================================================
set l=0
loop
set p=P[l]
set t=ModuloInteger(p,2)

set i=MultiboardGetItem(MB,l+3,0)
call MultiboardSetItemValue(i,GetPlayerName(Player(p)))
call MultiboardReleaseItem(i)
set i=MultiboardGetItem(MB,l+3,1)
call MultiboardSetItemValue(i,I2S(score))
if t==0 then
call MultiboardSetItemValueColor(i, 255, 0, 0, 255)
set kr=kr+score
set dr=dr+deaths
else
call MultiboardSetItemValueColor(i, 0, 0, 255, 255)
set kb=kb+score
set db=db+deaths
endif
call MultiboardReleaseItem(i)
set i=MultiboardGetItem(MB,l+3,2)
call MultiboardSetItemValue(i,I2S(deaths))
if t==0 then
call MultiboardSetItemValueColor(i, 255, 0, 0, 255)
else
call MultiboardSetItemValueColor(i, 0, 0, 255, 255)
endif
call MultiboardReleaseItem(i)

set l=l+1
exitwhen l==PLAYER_COUNT
endloop

set i=MultiboardGetItem(MB,1,1)
call MultiboardSetItemValue(i,I2S(kr)+"/"+I2S(SCORE_NEEDED))
call MultiboardSetItemValueColor(i, 255, 0, 0, 255)
call MultiboardReleaseItem(i)
set i=MultiboardGetItem(MB,1,2)
call MultiboardSetItemValue(i,I2S(dr))
call MultiboardSetItemValueColor(i, 255, 0, 0, 255)
call MultiboardReleaseItem(i)
set i=MultiboardGetItem(MB,2,1)
call MultiboardSetItemValue(i,I2S(kb)+"/"+I2S(SCORE_NEEDED))
call MultiboardSetItemValueColor(i, 0, 0, 255, 255)
call MultiboardReleaseItem(i)
set i=MultiboardGetItem(MB,2,2)
call MultiboardSetItemValue(i,I2S(db))
call MultiboardSetItemValueColor(i, 0, 0, 255, 255)
call MultiboardReleaseItem(i)
if kr>kb and kr>=SCORE_NEEDED then
call CustomVictoryBJ(Player(0),true,true)
call CustomVictoryBJ(Player(2),true,true)
call CustomVictoryBJ(Player(4),true,true)
call CustomVictoryBJ(Player(6),true,true)
call CustomVictoryBJ(Player(8),true,true)
call CustomDefeatBJ(Player(1),"Owned...")
call CustomDefeatBJ(Player(3),"Owned...")
call CustomDefeatBJ(Player(5),"Owned...")
call CustomDefeatBJ(Player(7),"Owned...")
call CustomDefeatBJ(Player(9),"Owned...")
endif
if kb>kr and kb>=SCORE_NEEDED then
call CustomVictoryBJ(Player(1),true,true)
call CustomVictoryBJ(Player(3),true,true)
call CustomVictoryBJ(Player(5),true,true)
call CustomVictoryBJ(Player(7),true,true)
call CustomVictoryBJ(Player(9),true,true)
call CustomDefeatBJ(Player(0),"Owned...")
call CustomDefeatBJ(Player(2),"Owned...")
call CustomDefeatBJ(Player(4),"Owned...")
call CustomDefeatBJ(Player(6),"Owned...")
call CustomDefeatBJ(Player(8),"Owned...")
endif

set i=null
endfunction
 
Status
Not open for further replies.
Top