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.

      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