HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

I cant get this trigger to work...

03-03-2003, 05:18 PM#1
MarSara
I made a trigger that takes a array of strings (names of heros) and extracts just the name part minus the color code and compares it to the players name, but it doesn't seem to work, anyway here is what I got. (always returns null)


(all strings are in this format: "|cffRRGGBBHeroName|r")


function Trig_PlayerHaveHero_TestName takes nothing returns nothing

local string s
local string t
local integer i
local integer j

// set index to location of "<null>" (udg_HeroNames[99])
set udg_HeroIDs[GetConvertedPlayerId(GetEnumPlayer())] = 99

// search threw all the strings
set i = 0
loop
exitwhen i >= 22

// find end of string (all strings have a
// color so search for ending |r
set j = 11
loop
exitwhen t == "|"

set t = SubStringBJ(udg_HeroNames[i],j,j+1)
set j = j + 1

endloop

set j = j - 1
set s = SubStringBJ(udg_HeroNames[i],11,j)

// match found, set current index to ID.
if(GetPlayerName(GetEnumPlayer()) == s) then
set udg_HeroIDs[GetConvertedPlayerId(GetEnumPlayer())] = i
endif

endloop

endfunction

function Trig_PlayerHaveHero_Actions takes nothing returns nothing

call ForForce( udg_Players, function Trig_PlayerHaveHero_TestName )

endfunction

//===========================================================================
function InitTrig_PlayerHaveHero takes nothing returns nothing
set gg_trg_PlayerHaveHero = CreateTrigger( )
call TriggerAddAction( gg_trg_PlayerHaveHero, function Trig_PlayerHaveHero_Actions )
endfunction
03-03-2003, 07:01 PM#2
Aiursrage2k
First thing I found was
Code:
exitwhen i >= 22
you never set i anywhere in this function, so it does not exit.
I suggest adding set i = i + 1, somewhere near the end of the function.

Second thing
Code:
loop
exitwhen t == "|"

set t = SubStringBJ(udg_HeroNames[i],j,j+1)
set j = j + 1

endloop
You are setting string 't' to contain two characters so I cannot see how the exit condition can ever be set to true. I would change the j+1 in SubStringBJ(...,j,j+1) to simply j.
if j = 1, set str = SubStringBJ("grunts",j,j+1), str would be gr not g
03-03-2003, 07:12 PM#3
MarSara
the set i = i + 1 was a typo, i originally had it there, but I found the error, it has something to do with running it at initlization (not in the actual code). Thanks anyway.