• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

I am trying to learn JASS but have questions

Status
Not open for further replies.
Level 5
Joined
Oct 11, 2009
Messages
125
This is the tutorial I am reading http://www.hiveworkshop.com/forums/...als-280/beginning-jass-tutorial-series-30765/

In part 2 which is about variables it gives this which I think will kill a unit

function variable_testA takes nothing returns nothing
local unit u = GetTriggerUnit()
call KillUnit(u)
endfunction

function variable_testB takes nothing returns nothing
call KillUnit(GetTriggerUnit())
endfunction

I put a footman in the middle of the map and copied this code but I dont see how I am supposed to make this kill the footman

oh another question
function HelloWorld takes nothing returns nothing
call BJDebugMsg("Hello World")
endfunction

i got this message to appear but i needed to use triggers to do it, how do i do it with just JASS
 
Level 12
Joined
Dec 10, 2008
Messages
850
TriggingUnit() returns the unit that "triggered" the trigger, making it start. You don't have a condition or Init (Used for registering Events, Conditions and Action functions), so it never gets called, and therfore doesn't work. Example:

JASS:
function variable_testA takes nothing returns nothing
local unit u = GetTriggerUnit()
call KillUnit(u)
endfunction

Is never fired, since it cant return unit u, and it isn't called to start with, now something like;

JASS:
Function ExampleCondition takes nothing returns boolean
return CallGetSpellAbilityID() == 'YourID'
endfunction 

function Example Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call KillUnit(u)
endfunction
There would also be an Init function, required for all spells to work properly, but you can learn that by converting GUI to JASS

The Condition makes sure that its supposed to call the Actions function, and passes the unit that started the event to it, becuase it started the trigger first.
 
Level 8
Joined
Jul 28, 2008
Messages
211
About the footman thing, if you want to do something to a placed unit, you can click on the unit and in the lower bottom corner you'll see it's name (something like h000_0000_0001) or you can make a GUI trigger and add an event (Unit event) and select that footman, then convert the trigger to JASS and you'll see what you need.

As for the message, you need an init trigger like Coolty said. You can make it run on map initialization:
JASS:
function InitTrig_Test takes nothing returns nothing
    call HelloWorld()
endfunction
If you want a trigger that happens when a unit casts a spell:
JASS:
function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' //'A000' is the rawcode of your spell
endfunction

function Trig_Spell_Actions takes nothing returns nothing
    //Do stuff - when you put // before your text, the editor will ignore that line. This is 
    //used for leaving comments in your trigger. Example:
    call KillUnit(GetTriggerUnit())
endfunction

function InitTrig_Spell takes nothing returns nothing
    local trigger t = CreateTrigger()    //I think you already know about locals (if not,
    //then skip this part, and read it later)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT) //This is
    //an event. You'll learn about those later too.
    call TriggerAddCondition(t, Condition(function Trig_Spell_Conditions)) //Condition
    call TriggerAddAction(t, function Trig_Spell_Actions)

If you don't understand this, keep reading the tutorial and then come back to this later. Good luck.

Oh by the way, get JNGP. It will make it MUCH easier. You'll have a list of functions in it, and you'll be able to name your functions more freely when you learn about scopes.
 
Status
Not open for further replies.
Top