My first JASS function.

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
I'm so happy; I've written my first JASS function.

Here it is:
JASS:
function purgeIdiots takes player idiot returns nothing
    local string idiotName
    set idiotName = GetPlayerName(idiot)
    if idiotName == "Atrum-Persavor" then
        call CustomDefeatBJ(idiot, "ahaha")
    endif
endfunction


I'm not quite sure about one thing, though, and note: I just finished reading the JASS tutorials and played around with JassCraft a bit.

I got my function, here. It's purpose, is to see if a player's name is Atrum-Persavor, then defeat him. (lol @ poor Atrum).

However, how do I make something to call the function, like, for example, like when the game's elapsed time is 3.00 seconds, or if a Footman enters a certain region?

Thanks in advance.

:D
 
J

JJ2197

Guest
Not the best solution... but whatever...

First make a function like:

function <whatever> takes nothing returns nothing
local integer i=0
loop
exitwhen i>11
call purgeidiots(player(i))
set i=i+1
endloop
endfunction

make sure this is under the function purgeidiots or you'll get a script error

and just add:
call <whatever>()
in function main, as long as it's under the locals it doesn't really matter where in it...
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Oh, no, that's not what I mean.

I mean, how do I call a function when an event (like a particular unit dying) ingame happens?
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Okay, I turned this:

Code:
trigger
    Events
        Unit - A unit enters (Entire map)
    Conditions
        (Unit-type of (Entering unit)) Equal to Footman
    Actions
        Unit - Cause No unit to damage (Entering unit), dealing 500.00 damage of attack type Spells and damage type Normal

into this:

JASS:
function Trig_trigger_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetEnteringUnit()) == &#039;hfoo&#039; ) ) then
        return false
    endif
    return true
endfunction

function Trig_trigger_Actions takes nothing returns nothing
    call UnitDamageTargetBJ( null, GetEnteringUnit(), 500, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endfunction

//===========================================================================
function InitTrig_trigger takes nothing returns nothing
    set gg_trg_trigger = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_trigger, GetEntireMapRect() )
    call TriggerAddCondition( gg_trg_trigger, Condition( function Trig_trigger_Conditions ) )
    call TriggerAddAction( gg_trg_trigger, function Trig_trigger_Actions )
endfunction


Okay, I can see how triggers are constructed now; but I'm still confused about one thing.

I can see that the first function is the condition; it checks if the UnitType of GetEnteringUnit() is equal to Footman.

The second function is obvious; it is the actions performed.

But this third function... it... creates a trigger? Why would it do that? And I'm not exactly sure why the function does this; I mean, I can tell that the next three lines, are adding the event, condition, and action to this newly created trigger... but why wouldn't it simply have the event, condition, and action inside the third function itself?
 
J

JJ2197

Guest
Okay...

I'll do it for a footman killed:

function whatever takes nothing returns nothing
if GetUnitTypeId(GetTriggerUnit())=='hfoo'then
call purgeidiot(GetTriggerPlayer())
endif
endfunction

To your question above, when it creates the trigger it's kinda like it's enabling it...
if it isn't ever created then it won't work...
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
But I don't understand how, in GUI, the event checks the conditions, then calls the actions; but how to actually code what to do when an event happens.
 

Vassilev

New Member
Reaction score
39
Code:
function InitTrig_trigger takes nothing returns nothing
    set gg_trg_trigger = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_trigger, GetEntireMapRect() )
    call TriggerAddCondition( gg_trg_trigger, Condition( function Trig_trigger_Conditions ) )
    call TriggerAddAction( gg_trg_trigger, function Trig_trigger_Actions )
endfunction

Ok, first of all, a trigger can ONLY HAVE:
a) 1 event
b) 1 condition
c) 1 Action

But if its only 1 condition and 1 action? how do people make more complicated triggers?

You create another function and call that function using the ONLY TriggerAddAction you have. Using this method, you can call any other trigger you want as long as its declared BEFORE the action trigger.

Example:

Code:
function EntangleTheUnit takes nothing returns nothing
call IssueTargetOrder(GetLastCreatedUnit(), "entangle" , GetTriggerUnit()
endfunction

function KillTheUnit takes noting returns nothing
call KillUnit(GetTriggerUnit())
endfunction

function MainAction takes nothing returns nothing
call EntangleTheUnit()
call TriggerSleepAction (5.00)    // (Wait)
call KillTheUnit()
endfunction

now going back to your code...

1) set gg_trg_trigger = CreateTrigger()

this code creates the trigger and "gg_trg" means its a global variable trigger

2) call TriggerRegisterEnterRectSimple( gg_trg_trigger, GetEntireMapRect() )

This NATIVE FUNCTION (TriggerRegisterEnterRectSimple) will assign a trigger named trigger to register the event whenever a unit enters the playable map area.

3)call TriggerAddCondition( gg_trg_trigger, Condition( function Trig_trigger_Conditions )

This NATIVE FUNCTION (TriggerAddCondition) will add a condition to the trigger named trigger

4) call TriggerAddAction( gg_trg_trigger, function Trig_trigger_Actions )
endfunction

This NATIVE FUNCTION (TriggerAddAction) will add an action(to the trigger named trigger) that should be taken once all the conditions are met.

So the steps are simple:
1) a trigger is created
2) you add which event you want it to register ( a unit dies? a unit enters a region? time elapsed?)
3) you add a condition to it
4) you add an action to it

So the result is:

1) An event happens
2) the condition is to filter out specific requirements
3) If the requirements are all satisfied
4) The action will be executed



P.S: Please do NOT name a trigger, "trigger" -_-"
 

0zaru

Learning vJASS ;)
Reaction score
60
>This NATIVE FUNCTION (TriggerRegisterEnterRectSimple)
That's not a native function.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>Ok, first of all, a trigger can [del]ONLY HAVE[/del]:
a) 1 event
b) 1 condition
c) 1 Action

Cut it out already.

>>2) call TriggerRegisterEnterRectSimple( gg_trg_trigger, GetEntireMapRect() )

This NATIVE FUNCTION (TriggerRegisterEnterRectSimple) will assign a trigger named trigger to register the event whenever a unit enters the playable map area.

Hey, don't misunderstood other people, it is a BJ function, not native.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Ahh, I see.
So the condition and the action is a function, but the event depends on what you add?

I'm beginning to understand much more clearly now.
 

Terrabull

Veteran Member (Done that)
Reaction score
38
The event is similar to a function, but it is something that the War3 engine does itself. It basically is told "Whenever you see this (insert Event here) let me know" by the trigger. Because it's built into the game's engine you can't modify it, all you can do is tell it what to watch for.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top