HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

2/2=2 ?

01-29-2007, 04:39 AM#1
The_AwaKening
I'm just trying to figure out why warcraft gives this answer. I'm using an integer level like so:

Collapse JASS:
set level = GetHeroLevel(u)    // the hero's level is 2
if level > 1 then
    set level = level / 2
endif
call SetHeroLevel(hero,level,false)

Output should be 1, but it is setting my new hero's level to 2. All the other numbers compute just fine. It's not a big deal, because I can work around it, but I just want to know why it happens like this.
01-29-2007, 05:05 AM#2
PipeDream
Insert debug message, press test map, continue
01-29-2007, 05:09 AM#3
Pyrogasm
I think it's because it's not actually setting the hero level to anything... Shouldn't call SetHeroLevel(hero,level,false) be call SetHeroLevel(u,level,false)?

That is, as long as "hero" isn't a variable; you're getting the level of "u" but setting the level of "hero".

Maybe?
01-29-2007, 06:04 AM#4
The_AwaKening
No, because that's not my actual code. It's 2 long triggers with different events, and the level is stored in gamecache. I was just breaking it down for posting.

Edit: After testing I realised that it is returning 1, but it is setting the hero level to 2. Why would that be?
01-29-2007, 09:18 AM#5
Pheonix-IV
Sounds like a bug in SetHeroLevel, i'd guess that for some odd coding reason SetHeroLevel can't be used to set a hero's level to 1, which seems odd, as the GUI trigger for setting a hero's level to 1 works fine and i'm fairly sure it's the same trigger. But if it's returning 1 and setting to 2, then you've got an issue somewhere in 'SetHeroLevel'

The other possibilities are that something else is acting on the variable Level or that another trigger is acting on the hero.
01-29-2007, 02:26 PM#6
shadow1500
Ehm:
Collapse JASS:
function SetHeroLevelBJ takes unit whichHero,integer newLevel,boolean showEyeCandy returns nothing
    local integer oldLevel = GetHeroLevel(whichHero)
    if (newLevel > oldLevel) then
        call SetHeroLevel(whichHero, newLevel, showEyeCandy)
    elseif (newLevel < oldLevel) then
        call UnitStripHeroLevel(whichHero, oldLevel - newLevel)
    else
    endif
endfunction
01-29-2007, 02:45 PM#7
Rising_Dusk
Yeah, SetHeroLevel() cannot reduce a hero's level.
You have to use UnitStripHeroLevel() as Shadow has so graciously shown.

(Sure I'm being repetetive, but I didn't think Shad's post was as self-explanatory as it could have been)
xD
01-29-2007, 06:55 PM#8
The_AwaKening
Well that's going to be good to know, but here is another thing. The problem I'm having is not addressed in the BJ function at all. If newlevel==oldlevel. I tried this in a test map as well using no other triggers except for one to test. If you have a level 1 hero and try using SetHeroLevel(u,1,false), it sets the hero level to 2. Easy to work around, but just kind of odd that it does that.