Some Simple Questions

Charapanga

New Member
Reaction score
46
Ok, so i'm a reaaaal noob at this so...

1. How many spaces do i need to do before i do an action? Example:
JASS:
function SomeFunc takes nothing returns nothing
<How many spaces> call ...
endfunction


2. Can i set locals in a normal function or do i need to do something else, if i'm only setting locals?Can i do (example)
JASS:
function Variables takes nothing returns <variables>
local unit blabla
endfunction

Or must i do something else?

3. What's Jass Language for:
Picked unit
Matching unit
Dying unit

That's all for now, will be adding ALOT more, since i just started this

Oh and don't be fooled, i've read some of the Tutorials, so i know the basics :)
 

gameman

It's been a long, long time.
Reaction score
95
the number spaces can be there to make it easier to read, it doesn't matter how many, and they do nothing for the trigger.
And locals can be set in any function.

Picked unit = GetEnumUnit()
Matching unit = GetFilterUnit()
Dying unit = GetDyingUnit()
 
Reaction score
456
> How many spaces do i need to do before i do an action?
None. But to make your code readable, it has to indented in some way. Use Tab for it.

> Can i set locals in a normal function
What is not a normal function? But you cannot return "<variables>", though.

Picked unit - GetEnumUnit()
Matching unit - GetFilterUnit()
Dying unit - GetTriggerUnit() / GetDyingUnit()
 

Charapanga

New Member
Reaction score
46
Oooh, i tought it was important...Thanx!

EDIT:
>What is unnormal function?
I saw Libraries, and globals...
Those end with endlibrary and endglobals

and Thanx!
 

Charapanga

New Member
Reaction score
46
Oh...Thanx!
Theres another thing...
Why declare Globals when you can have Locals?
And what's a 'Map header'?
 

Charapanga

New Member
Reaction score
46
Oh...and Locals are just for a Function?
And that function then has to Return it?

Sorry, i don't fully understand how Locals work, i only know that they make a spell MUI :D
 

gameman

It's been a long, long time.
Reaction score
95
I think that the locals use are for only the trigger that there declared in. so I don't think they can be returned.
 
Reaction score
456
> I think that the locals use are for only the trigger that there declared in. so I don't think they can be returned.
Don't think like that. Trigger is only a variable type when talking about Jass. This is complete nonsense.

> Oh...and Locals are just for a Function?
Yes. They're only for the function you declared them in. But they can always be transferred:

JASS:
function Func2 takes integer i returns nothing
     call BJDebugMsg(I2S(i)) // displays 25
endfunction

function Func1 takes nothing returns nothing
     local integer i = 5 * 5
     call Func2(i)
endfunction


> And that function then has to Return it?
It doesn't have to, but it can.

> i only know that they make a spell MUI
Not really.
 

Charapanga

New Member
Reaction score
46
Thanx for the replies! Shed some light on the subject...

Next question...4. was it?
I was looking at Function List an i saw 2 types of them, one is Native, other is bj, what's the difference?
 

Flare

Stops copies me!
Reaction score
662
Probably easiest to explain BJ's first :D

BJ functions are (generally) functions that call native functions - this can be both good and bad, depending on the BJ. The bad BJ's are things like
JASS:
function UnitCanSleepBJ takes unit whichUnit returns boolean
    return UnitCanSleep(whichUnit)
endfunction

Looks quite pointless doesn't it? All it's doing is returning the native function that it's associated with, and there's nothing stopping you from just using the native function since it's more efficient to call one function instead of two.

Then, there are some 'good' BJ's, which have a similar effect (i.e. calling an equivalent native function), but they usually have numerous function calls built into the BJ (even though those 'good' BJ's can also contain the bad ones as well :() e.g.
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction

Ignoring the fact that this function actually leaks, even though it's fairly insignificant unless you're using it VERY heavily
Alot of work is being done in that function, and it's much easier to just do
JASS:
call TriggerRegisterAnyUnitEventBJ (whichTrigger, whichPlayerEvent)

than type out all that code, declare a filter, and go through the whole process of doing it the non-BJ way, which does make it a relatively good BJ (apart from the aforementioned leak, but that number of leaks is tiny compared to the number you need before you actually suspect you have leaks)

And, generally, BJ functions are usually easier to handle at first (since the 'sensible' range of values you can use for the parameters seem far more logical than with some natives) e.g.
JASS:
function TextTagSpeed2Velocity takes real speed returns real
    return speed * 0.071 / 128
endfunction


function SetTextTagVelocityBJ takes texttag tt, real speed, real angle returns nothing
    local real vel = TextTagSpeed2Velocity(speed)
    local real xvel = vel * Cos(angle * bj_DEGTORAD)
    local real yvel = vel * Sin(angle * bj_DEGTORAD)

    call SetTextTagVelocity(tt, xvel, yvel)
endfunction

Quite simple - you give an angle, and a speed, and you're done - with the native, you have to calculate the X velocity and Y velocity, which can be really confusing at first, especially when coupled with the fact that the value for that vel variable seems odd - if, say, you had 64 speed with the BJ, it'd be 0.0355, which can't really be compared to the speed of anything else in WC3, can it, but 64 sounds somewhat logical by comparison (0.0355 would give me the impression that it's going to be snail slow, which probably won't be the case)

Then, you have your utility BJ's e.g.
JASS:
function BJDebugMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,60,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction

function RMaxBJ takes real a, real b returns real
    if (a &lt; b) then
        return b
    else
        return a
    endif
endfunction

BJDebugMsg is great for when you need to fix code (since it's very simple and quick to use, due to the fact that it has a single parameter), and something like RMaxBJ (and it's integer equivalent IMaxBJ) are pretty handy for easily retrieving the maximum value of two variables, rather than having to do it manually in your code (which could just end up making your code confusing to read)


And then you have natives, which don't call any other (JASS) functions when they are called - not a whole lot of explaining there :p
 

Charapanga

New Member
Reaction score
46
You could make this into a tutorial!
Thanx for the help! Appreciate it man!
+rep fo' sho'!

Another question... 5. What's the difference of making the trigger in 1 function or if making it in more functions? Example
JASS:
function SomeFunc1 takes nothing returns nothing
    call ...
endfunction

function SomeFunc2 takes nothing returns nothing
   get ....
endfunction

function SomeFunc3 takes nothing returns nothing
    set ...
endfunction

// Or....

function allinone takes nothing returns nothing
    call ....
    get ....
    set ....
endfunction
 

Flare

Stops copies me!
Reaction score
662
Well, for multiple functions.
1) Less efficient if you have something that could be done in a single function, separated into a number of functions (due to additional function calls required to complete the stuff)
2) No access to locals from previous functions (even though this can be worked around with globals and/or function parameters, whichever is applicable in the situation)

So, if I'm able to do everything I need within one function, I will

So, if you were making a simple spell, I would usually have 3 function - the Init function (I think it's InitTrig_TriggerName when converted from GUI) for events, actions, conditions setup, a condition function (for handling the conditions that are required) and the actions function, for carrying out the stuff that the spell does e.g.
JASS:
//EXTREMELY simple, won&#039;t even bother with something that neccesitates the usage of variables <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
//I could split up the action function, but it&#039;d be silly since I can easily just handle everything within the one function
//(and this situation won&#039;t change as the function gets bigger)
function ActionFunc takes nothing returns nothing
  call UnitDamageTarget (GetTriggerUnit (), GetSpellTargetUnit (), 100, false, true, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
  call DestroyEffect (AddSpecialEffectTarget (&quot;Insert\\Modelfile\\here.mdl&quot;, GetSpellTargetUnit (), &quot;chest&quot;))
endfunction

function CondFunc takes nothing returns nothing
  return GetSpellAbilityId () == &#039;A000&#039;
endfunction

function InitTrig_MyTrigger takes nothing returns nothing
  local trigger t = CreateTrigger ()
  call TriggerRegisterAnyUnitEventBJ (t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
  call TriggerAddCondition (t, Condition (function CondFunc))
  call TriggerAddAction (t, function ActionFunc)
endfunction


If you were making something more complex, you would need things like group enumeration filters, group callbacks, timer callbacks, and there is little you can do to avoid having to declare an extra function for those (even though groups can be handled completely within the enumeration filter), particularly timers since there isn't much (if anything) equal to it as regards precision (loop and waits won't cut it at all by comparison)
 

Charapanga

New Member
Reaction score
46
Oooh, now i get it!
But wait..i didnt understand some stuff like
Enumeratin filters
group callbacks
timer callbacks

Oh, and how can i make a Periodic time event within a trigger that has the event Player unit spell effect? Make a loop that calls another function or...?
Oh and how can i make a loop that stops in 5 secs? since i can't do Turn on trigger wait 5 seconds turn off trigger...
 
Reaction score
341
Oh, and how can i make a Periodic time event within a trigger that has the event Player unit spell effect? Make a loop that calls another function or...?

Just create the GUI version of the events... And convert to custom text.

Oh and how can i make a loop that stops in 5 secs

JASS:
function loopstuff takes nothing returns nothing
loop
  exitwhen udg_boolean = false
    // actions
endloop
endfunction

function startloop takes nothing returns nothing
    set udg_boolean = true
    call loopstuff()
    call TriggerSleepAction(5.00)
    set udg_boolean = false
endfunction
 

Charapanga

New Member
Reaction score
46
That's a great idea for a whole other trigger inside the main one! i might have to change all my knockback spells :D
Thanx!

Another question: 6, was it? How do i set up the trigger, the whole InitTrig_My_Trig?
and where can i find translations of Events such as:
Periodic time event
Unit enters Region
Unit takes damage < Can this one be done without setting the specific unit thing like in GUI?(Specific unit event, there is no generic unit event 'Unit takes damage')
 

Charapanga

New Member
Reaction score
46
Oh, right...stupid me *faceslap*
but that still doesn't anwser my question of making a specific unit event into a generic one
 
Reaction score
341
... Still the same answer... Make it in GUI then convert.

Event - Unit is attacked

Convert it... will show you the jass version
 
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