• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] a function that return wrong value

Status
Not open for further replies.
Level 9
Joined
Dec 12, 2007
Messages
489
hello guys,
this is about my project map, titled "Chaos Legion",
few days ago everything seems to go well, until i noticed
something strange happen with the hero selection,

the hero selection system in the map is goes by:
1. a tavern that sold the Legion that the Hero will own,
2. each Legion(s) will be different by amount of units and hero that
control them.
3. when user pick the Legion, the Legion is moved to the spawn spot and
check what Legion it is then creates a corresponding hero beside it, and
create few another Legion with it, assign the Legion into a struct then
then hide them for use with the Summon ability on the hero.
4. the way i check what corresponding hero of the legion and the number of
Legion is on the map init, i assign 3 array, each one is Legion's unit id,
the hero's id, and the number of Legion created. and when the Legion
picked, i loop through those array checking the Legion's unit id to obtain
the array index of the Legion, and then create the hero etc.

i have narrowed the problem and found out that everything gone well
except point 4, which when the function is called, it always return index 0,
the function is :
JASS:
library LegionData initializer init
    globals
                 integer array HERO_LEGION
        constant integer       HERO_TOTAL       = 7
    endglobals

    private function legion takes nothing returns nothing
        set HERO_LEGION[0] = 'O000'
        set HERO_LEGION[1] = 'O001'
        set HERO_LEGION[2] = 'O002'
        set HERO_LEGION[3] = 'O003'
        set HERO_LEGION[4] = 'O005'
        set HERO_LEGION[5] = 'O004'
        set HERO_LEGION[6] = 'O006'
    endfunction

// the "takes integer id" is taking the Legion's unit rawcode
    function GetLegionIndex takes integer id returns integer
        local integer i = 0
        local integer x = 0
        loop
            exitwhen i > HERO_TOTAL
            if (HERO_LEGION[i] == id) then
                set x = i
            endif
            set i = i + 1
        endloop
        return x
// here lies the trouble, the returned value is always 0
    endfunction

    private function init takes nothing returns nothing
        call ExecuteFunc(SCOPE_PRIVATE+"legion")
    endfunction
endlibrary

i have wasted few days to spot where i did wrong, but still unable to find out.
so i need someone to help me find where the fail is, thanks before
 
Level 9
Joined
May 27, 2006
Messages
498
Isn't it quite obvious? The if-then-else check fails, the compared ids' aren't equal to each other, therefore x never gets a new value.
Anyway, this works well for me. I put it into map header and did call BJDebugMsg(I2S(GetLegionIndex('O003'))) on map initializaton, it returned correct value, 3.
Are you sure that you're giving it the correct id?
 
Level 9
Joined
Dec 12, 2007
Messages
489
aaaa... damnit...
thx for putting me back on my senses,
i found out the problem thanks,
the problem lies with:
JASS:
    private function legion takes nothing returns nothing
        set HERO_LEGION[0] = 'O000'
        set HERO_LEGION[1] = 'O001'
        set HERO_LEGION[2] = 'O002'
        set HERO_LEGION[3] = 'O003'
        set HERO_LEGION[4] = 'O005'
        set HERO_LEGION[5] = 'O004'
        set HERO_LEGION[6] = 'O006'
    endfunction
it should be:
JASS:
    private function legion takes nothing returns nothing
        set HERO_LEGION[0] = 'o000'
        set HERO_LEGION[1] = 'o001'
        set HERO_LEGION[2] = 'o002'
        set HERO_LEGION[3] = 'o003'
        set HERO_LEGION[4] = 'o005'
        set HERO_LEGION[5] = 'o004'
        set HERO_LEGION[6] = 'o006'
    endfunction
thx again n +rep for you.. hehe

so the case is closed...
 
Status
Not open for further replies.
Top