Help with first JASS function

Spiteless

New Member
Reaction score
0
Help with first JASS function - Updated

Hey, I finally took the time to write a JASS function, I have some errors that are making me go :banghead: though, hopefully someone can help me out.

The aim of the function is to have a unit purchase an item to learn a skill (such as tome of critical strike in this case) and here's, code:

JASS:
scope CriticalStrike initializer Init

    globals
        private constant integer itemID = 'I002' //item ID
        private constant integer abilID = 'AOcr' //ability ID
        private constant integer cost = 0 //return cost if error in purchase
        private constant integer abilmaxlv = 3 //max ability level
      //private constant real abilmaxc = 7 //max number of abilitys per unit -- unused atm
    endglobals
    
    private function True takes nothing returns boolean
    return true
    endfunction

    
    private function Cons takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == itemID
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        local integer l = GetUnitAbilityLevel(u, abilID)
    if (l == abilmaxlv ) then
        call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD) + cost ) )
    else
    if l < abilmaxlv 
        call SetUnitAbilityLevel(u, abilID, GetUnitAbilityLevel(u)+1)
    else
    UnitAddAbility(u, abilID)
    endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i > 15
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Filter(function Cons))
        call TriggerAddAction(t, function Actions)
    endfunction
endscope


One error: "Syntax error" on this line:
JASS:
if l < abilmaxlv

Any more pointers?
 
Reaction score
341
JASS:
    if (lol == abilmaxlv ) then
        call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD) + 1 ) )
    else
    if (lol < abilmaxlv ) then
        call SetUnitAbilityLevel(u, abilID, GetUnitAbilityLevel(u)+1)
    else


Change to

JASS:
    if (lol == abilmaxlv ) then
        call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD) + 1 ) )
    elseif lol < abilmaxlv 
        call SetUnitAbilityLevel(u, abilID, GetUnitAbilityLevel(u)+1)
    endif


Then remove this function

JASS:
    private function True takes nothing returns boolean
    return true
    endfunction


and change the event to

 

Trollvottel

never aging title
Reaction score
262
JASS:
    
Then remove this function

<div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass">    <span class="keyword">private</span> <span class="keyword">function</span> <span>True</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/boolean" class="type">boolean</a>
    <span class="keyword">return</span> <span class="value">true</span>
    <span class="keyword">endfunction</span></code></pre></div></div>

and change the event to

<div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerRegisterPlayerUnitEvent" class="native">TriggerRegisterPlayerUnitEvent</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/Player" class="native">Player</a><span class="symbol">(</span><span>i</span><span class="symbol">)</span><span class="symbol">,</span> <a href="http://wiki.thehelper.net/wc3/EVENT_PLAYER_UNIT_ATTACKED" class="variable">EVENT_PLAYER_UNIT_ATTACKED</a><span class="symbol">,</span> <span class="value">null</span><span class="symbol">)</span></code></pre></div></div>
JASS:

DONT do that...
 

Romek

Super Moderator
Reaction score
963
The BJ leaks.
You're telling him to make his code leak.
If he was going to do that, he might as well have used TriggerRegisterAnyUnitEventBJ(..)

Basically the only reason why people add the event like that is to remove the leak, otherwise it'll be easier to just use the BJ.
 

Romek

Super Moderator
Reaction score
963
Well, i didn't know it leaked. (Learn something new everyday..)
Passing "null" as a boolexpr leaks.
That's the only reason functions which do nothing except return true where created.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top