• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

My first JASS adventure

Status
Not open for further replies.
Level 3
Joined
Mar 4, 2018
Messages
29
I am looking to design, among other future migraine inducers, an intricate aura. I'm starting with some baby steps and simply trying to make it so that if one hero is within 1000 distance of a certain other hero, they automatically learn a skill that grants them 5 int. If they leave this distance, they unlearn the skill again. I decided on this approach rather than just simply modifying the base int partly because I like that it's a green added number so you know it's a bonus, and partly because I expect it has less potential to bug out and permanently add or remove int.

So from looking at Blizzard-generated code and other people's code and changing things until I stopped getting error messages, I have arrived at the following creation.

Code:
function Augment takes nothing returns nothing
    local unit u=gg_unit_H000_0006
    if (IsUnitInRange(u,gg_unit_H001_0004, 1000)) then
        call SetUnitAbilityLevel(u,'A00A',1)  
    else
        call SetUnitAbilityLevel(u,'A00A',0)
    endif
    set u=null
endfunction

And now let's talk about it. Firstly, I don't know where these unit names come from, I only figured them out by manually clicking the heroes with the GUI. Secondly, I believe I didn't need to introduce the variable u but some voices in my head are telling me that this will be needed later so that the "aura" can check for any allied unit.

But what's bugging me is why is this not enough? Blizzard wouldn't let me save the map with this trigger, so I pasted it into an empty Blizzard trigger and tinkered with it so it now looks like

Code:
function Augment takes nothing returns nothing
    local unit u=gg_unit_H000_0006
    if (IsUnitInRange(u,gg_unit_H001_0004, 1000)) then
        call SetUnitAbilityLevel(u,'A00A',1)  
    else
        call SetUnitAbilityLevel(u,'A00A',0)
    endif
    set u=null
endfunction

//===========================================================================
function InitTrig_Augment takes nothing returns nothing
    set gg_trg_Augment = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Augment, function Augment )
endfunction

I haven't made a trigger since StarCraft 1, but it seems to me I have a condition (a hero comes within a range of another) and something that happens if that is met, so I don't know why I need this gibberish afterwards.

But moving on, even having progressed to the point that I get no error messages, it's not actually doing anything in-game. I'll have you know that the great heroine known to you as gg_unit_H000_0006 does have the int bonus skill available to her and the trigger works when I design it with the GUI, but 1) I can only learn the skill with the GUI, not unlearn and 2) I'm reading pretty much everywhere that the GUI is inferior so I should not use it over code.

And lastly, with the GUI trigger it actually spent our great heroine gg_unit_H000_0006's initial skill point to learn the int boost, which also isn't intended behavior.

My body is ready to hear all the ways I suck at coding and there's plenty of lube available, but please do go easy on me.
 
Last edited:
Level 7
Joined
Mar 10, 2013
Messages
366
So, I wouldn't go as deep in code to explain how Warcraft 3 engine works with a Jass in specific, but what I will apply to almost every kind of programming done.

All Wc3 triggers are event oriented, so in order to the code you've done work, it needs to be triggered by something.

Basically what all init triggers do is:
  1. Create a trigger object
  2. Add the events that will fire this trigger object
  3. Add the conditions in which the actions related to the trigger might or not fire
  4. Add the actions that will happen when the events fired the trigger object AND verified that the conditions in which those actions should be fired are TRUE
That what all GUI trigger structures shows to you.

In jass it's the exact same thing.

In your case, there's no event trigger attached to your trigger object, so there's no wonder why your trigger doesn't work it never knows when to fire the actions.
Now, in your example, probably the timer structure would be the better case scenario for you instead of an event (since we've no event like: "when unit gets near other unit")

JASS:
function Augment takes nothing returns nothing
    local unit u=gg_unit_H000_0006
    if (IsUnitInRange(u,gg_unit_H001_0004, 1000)) then
        call SetUnitAbilityLevel(u,'A00A',1)  
    else
        call SetUnitAbilityLevel(u,'A00A',0)
    endif
    set u=null
endfunction

//===========================================================================
function InitTrig_Augment takes nothing returns nothing
    local timer t = CreateTimer()
    // timer object, time to elapse, is periodic and function handler
    call TimerStart(t, 1.00, true, function Augment )
    set t = null
endfunction

You probably want to always check JASS Manual: API Browser - API Browser: Types to see what kind of tools you're able to use in jass.
 
Level 3
Joined
Mar 4, 2018
Messages
29
Cheers. I've just been browsing the JassCraft natives list looking for names that sound like they might cooperate with what I'm trying to achieve. So the second function makes the fire trigger repeatedly after 1 second of game time, is that right?

Anyway... it's still not doing anything in-game. :/

P.S.
(since we've no event like: "when unit gets near other unit")
My GUI trigger was
Clipboard01.jpg

so this sounded confusing to me.
 
Level 3
Joined
Mar 4, 2018
Messages
29
A little undecided there. On the one hand it sounds like it will be the best solution in the long run, but for now it's hard for me to understand how to use it and I will end up with even more questions than I have here. Also it seems I would need a different way of granting the int buff than a custom ability since I don't see a way of removing it with that system. How would you do it? This custom ability solution is giving me other problems, for example I want the ability button to be hidden on the "learn page" of the command card but it isn't.

With all due respect, to my very inexperienced eyes I actually don't even see how it is practically different from the GUI trigger I made.

Edit: Hell, this would be super smooth if I could just make a custom aura that buffs int instead of this pseudo-aura-range-detection project, but I'm guessing it can't be done that easily. UnitHasBuffBJ GetUnitAbilityLevel looks interesting...
 
Last edited:
Level 11
Joined
May 16, 2016
Messages
730
I am looking to design, among other future migraine inducers, an intricate aura. I'm starting with some baby steps and simply trying to make it so that if one hero is within 1000 distance of a certain other hero, they automatically learn a skill that grants them 5 int.
 

Attachments

  • SMTH AURA.w3x
    17.9 KB · Views: 61
Level 3
Joined
Mar 4, 2018
Messages
29
Oh, that is awesome Fruit Forest, thanks! Gonna look into this until it all makes sense now.

Just discovered the button to hand out rep and it's well about time I did.
 
Level 7
Joined
Mar 10, 2013
Messages
366
Cheers. I've just been browsing the JassCraft natives list looking for names that sound like they might cooperate with what I'm trying to achieve. So the second function makes the fire trigger repeatedly after 1 second of game time, is that right?

Anyway... it's still not doing anything in-game. :/

P.S.

My GUI trigger was
View attachment 293687
so this sounded confusing to me.

Sorry I kind of forgot that was possible to use.

Well the problem is, you're using Learn instead of Add Ability.

Learning implies that a unit already have that ability (of type hero) and it's passible to be learned.

What you're looking for is
upload_2018-3-10_16-3-2.png


And its native counterpart in jass:
JASS:
native UnitAddAbility (unit whichUnit, integer abilityId) returns boolean
 
Status
Not open for further replies.
Top