• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Leaderboard Help

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I can't seem to figure out why this script doesn't work:

JASS:
library CreepCounter

    private function GroupConditions takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) != DUMMY_ID and GetOwningPlayer(GetFilterUnit()) == Player(11)
    endfunction

    public function Create takes nothing returns nothing
        local integer count = 0
        
        set creepCounter = CreateLeaderboard()
        call GroupEnumUnitsInRect(enumG, bj_mapInitialPlayableArea, Condition(function GroupConditions))
        
        for enumU in enumG
            set count = count + 1
        endfor
        
        call LeaderboardAddItem(creepCounter, "Creeps left:", count, Player(11))
        call LeaderboardSetItemStyle(creepCounter, 1, true, true, false)
        call LeaderboardSetItemLabelColor(creepCounter, 1, 100, 80, 0, 256)
        call LeaderboardSetItemValueColor(creepCounter, 1, 100, 80, 0, 256)
        call LeaderboardDisplay(creepCounter, false)
        call LeaderboardDisplay(creepCounter, true)
    endfunction

endlibrary

creepCounter has been declared as a global elsewhere. When I run this with a debug message, it counts the number of creeps correctly, but does not display the leaderboard at all. Any ideas?

Thanks,

Mr_Bean
 
Level 13
Joined
Sep 13, 2010
Messages
550
First of all: Apply the code that FlashBond posted.

JASS:
        call LeaderboardSetItemLabelColor(creepCounter, 1, 100, 80, 0, 256)
        call LeaderboardSetItemValueColor(creepCounter, 1, 100, 80, 0, 256)

The 256 is invalid value for a 0-255 value, your text will be invisible :D Also if you want it to apply for the first line you have to put 0 instead of 1( stupid thing again from blizzard ). Furthermore you have to use call LeaderboardSetSizeByItemCount( creepCounter , /* use this native, or the exact amount. */ LeaderboardGetItemCount( creepCounter ) ) to display properly. Also creating a leaderboard only work after game started( 0.0 timer/wait is enough ).
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Add this line when setting up the leaderboard:

call PlayerSetLeaderboard(YOUR_PLAYER, creepCounter)

Thanks man, this helped!

First of all: Apply the code that FlashBond posted.

The 256 is invalid value for a 0-255 value, your text will be invisible :D Also if you want it to apply for the first line you have to put 0 instead of 1( stupid thing again from blizzard ). Furthermore you have to use call LeaderboardSetSizeByItemCount( creepCounter , /* use this native, or the exact amount. */ LeaderboardGetItemCount( creepCounter ) ) to display properly. Also creating a leaderboard only work after game started( 0.0 timer/wait is enough ).

It seemed to work with an alpha value of 256, but I fixed it anyway. Thanks, setting the size is something I was missing.
 
Level 6
Joined
May 13, 2009
Messages
260
Also if you want it to apply for the first line you have to put 0 instead of 1( stupid thing again from blizzard ).
I looked up a good explanation for this and it's because of offsets. Because memory starts directly at the specified memory address, not 1 byte after. So if you make a computer language that starts all indexes with 1 the interpretor needs to subtract 1 or leave the first element blank. But that would be very inefficient.

Thanks for making me learn things :)
 
Status
Not open for further replies.
Top