• 🏆 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] [Snippet] powerupSENTINEL

Level 13
Joined
May 11, 2008
Messages
1,198
Nothing special, just dealing with Items of the "Powerup" type. Not sure if it's efficient or not, but it deals with memory leaks and that can't be a bad thing.

JASS:
scope powerupSENTINEL initializer I//by SanKakU, original made by Vexorian
//his version is not even vJASS and i changed some parts of it besides translating, 
// but he had the right idea first//to quote him:
 /*  Powerup items don't get removed automatically by the game, they instead
just leave a small item in the map, this caused memory leaks but - worse -
it also makes areas of your map where a lot of tomes have been used lag a lot.*/
  
  private function F takes nothing returns nothing
        if GetWidgetLife(GetManipulatedItem()) == 0 then
            call RemoveItem(GetManipulatedItem())
        endif     
    endfunction

    private function I takes nothing returns nothing
        local trigger T = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( T, EVENT_PLAYER_UNIT_PICKUP_ITEM )//because it works on item pickup, it only works on modern style powerups that are immediately used instead of also the old ones which had to be clicked after picking them up to use them
        call TriggerAddAction( T, function F)
    endfunction

endscope
 
Last edited:
Level 13
Joined
May 11, 2008
Messages
1,198
Level 13
Joined
May 11, 2008
Messages
1,198

Oh, you know at first sight, it looks like that guy did a lot more research then me! At any rate, structs are confusing to me.

What does he mean by manually-destroyed items? Is that like when your hero attacks an item? Or is it something else?

I have my doubts about the system's authenticity because he posts 2 things that don't make sense together:

So, in order to properly destroy an item, you have to set its life to more than 0.405 before trying to remove it.
With
If you set their life to more than 0.405, they won't be properly cleaned.

Anyway, the guy links a resource that is currently in the graveyard and his code seems to be lacking data?
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
The resource he linked to is currently on GitHub. The Item Cleanup system is legitimate. A lot of people have used it in their maps. Simply cnp the system and it will clean the items =).

If you want to find missing resources, google something like WorldBounds JASS and it'll usually be the first link.

Improper names are no longer acceptable. This has been the case since Vexorian fixed his optimizer.

private function F takes nothing returns nothing

Your documentation is essentially a wall of text, making it difficult to read. You don't need to change this, but if you want people to read it, you should : p.

JASS:
//by SanKakU, original made by Vexorian
//his version is not even vJASS and i changed some parts of it besides translating, 
// but he had the right idea first//to quote him:
 /*  Powerup items don't get removed automatically by the game, they instead
just leave a small item in the map, this caused memory leaks but - worse -
it also makes areas of your map where a lot of tomes have been used lag a lot.*/

Non-constant variables are always pascal case.

local trigger T = CreateTrigger( )

Extremely long lines are frowned upon (see scrollbars are bad tip in my quote lower in this post).

call TriggerRegisterAnyUnitEventBJ( T, EVENT_PLAYER_UNIT_PICKUP_ITEM )//because it works on item pickup, it only works on modern style powerups that are immediately used instead of also the old ones which had to be clicked after picking them up to use them

Here are some tips** (not requirements) from my old comments guide

More Examples
JASS:
/*
*   Nobody likes to read a block of text, so avoid them.
*
*   Group common text together
*
*   Avoid lots of small lines
*   -----------------------
*
*       Like this
*       And this
*       And this
*       It's just irritating
*       Do you see how irritating this gets?
*       It's almost like a hyperactive
*       Little
*       Kid
*       That
*       You
*       Just
*       Want
*       To
*       Punch
*       OMG MAKE IT STOP
*
*   Make lists
*   -----------------------
*
*       1. I am important
*       2. You all know that I am important and awesome
*       3. I am just sick
*       4. This list is actually nice to read
*
*   Don't make whacked essays
*   -----------------------
*
*       Do whatever you can to avoid a block of text because NOBODY likes a block of text.
*       Like this here is a crazy block of text that you will likely never read.
*       This is just more text that you'll have to read through in order to get the main
*       point of whatever is below this text. It'd almost be faster, in fact it would be
*       faster to just decipher the code rather than to sit through this huge long
*       essay that you just don't want to read because reading takes time and nobody has
*       time to spare on your long wordy words for short things. And finally I reach my point.
*       The below line, yes, the below line, will add EXACTLY 1 to the variable because I say it will.
*       Oh my, you must be very upset with me right now, but I want my lesson to be very clear.
*       NOBODY LIKES BLOCKS OF TEXT
*
*   Always make clear and informative comments. I can see that you are increasing some
*   variable by one. What I want to know is WHY you are increasing it, not that you are increasing it.
*   You don't need to explain that you have just added 1 to a variable.
*
*/
    set myAwesomeVariable = myAwesomeVariable + 1
    
/*
*   More pointless explanations
*/

/*
*   This is a method that takes nothing and returns nothing
*/
method something takes nothing returns nothing
endmethod

/*
*   This is an integer that I add 1 to every time I go through a loop
*/
local integer thisIsMyIntegerThatIAddOneToEveryTimeIGoThroughALoop = 0
loop
    set thisIsMyIntegerThatIAddOneToEveryTimeIGoThroughALoop = thisIsMyIntegerThatIAddOneToEveryTimeIGoThroughALoop + 1
    
    /*
    *   I am going to loop 500 times
    */
    exitwhen thisIsMyIntegerThatIAddOneToEveryTimeIGoThroughALoop == 500
endloop

/*
*   Good explanations
*/

/*
*   Do a method header here!
*/
method something takes nothing returns nothing
endmethod

/*
*   Initialize first 500 instances to improve performance
*/
local integer instance = 0
loop
    set instance = instance + 1
    exitwhen instance == 500
endloop

Scrollbars Are Bad
JASS:
/*
*   Never make a line that is so long that it causes a scrollbar. It is really annoying to have to scroll back and forth in order
*   to read really long comments. Learn when to break your lines so that you can avoid the infamous scrollbar. Hopefully you can
*   see by this just how annoying it is to scroll back and forth. Apply this lesson to all code. If you have a really long method call, be sure to split it up by using /* */.
*   The editor will continue to show text that will not show within the width of the JASS box on forums, so use your best judgment. If you see a scrollbar for your code in the JASS box, then modify your code to get rid of the scrollbar until that bar goes away.
*/

The following are library header styles ; ). There are many. I recommend you always include a library header with any submission ; ). This isn't required, but a header does make the submission look a lot better. I believe just about all of the veterans here at THW always include a header ; ).

You can find IcemanBo's style here

http://www.hiveworkshop.com/forums/spells-569/terraininfection-v2-1-a-259271/?prev=d=list&r=20&c=112

usd99's style

http://www.hiveworkshop.com/forums/...-v1-2-a-260603/?prev=c=112&r=20&d=list&page=2

nestharus style

http://www.hiveworkshop.com/forums/...ocation-260897/?prev=c=112&r=20&d=list&page=3

wc3c style

http://www.wc3c.net/showthread.php?t=104464


The older styles from wc3c and thehelper tend to use lots of single line comments and large blocks of text. The newer styles from THW tend to use multiline comments with *'s and lists.
 
Last edited:
Top