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
964
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
964
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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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