• 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.

[JASS] Little tricks about "returns" and advanced triggers

Status
Not open for further replies.
Level 2
Joined
Jun 5, 2006
Messages
18
Ok...i'm really new on JASS, but i create programs in c++, javascript and things like this...

i would like to do a very easy thing: take a value on a function (an integer) from a global (udg_bla) and return a real (that i will use to get the time)...i'm using WE unlimited, so i can run the function directly inside the action Wait X

that's the code that i'm trying to use...but there are something that it's not correct

JASS:
function FDDspellinfoDELAY takes integer i returns real
local real R = 0.00
if i == 0 then
set R = 2.00
endif
return R
set R = null
endfunction

FIRST

set R = null it's not an action that can stay after a return (it's never read)...but i can't return a value if i do it BEFORE the return...so, what should i do for this?

SECOND

if i would like to return a TRIGGER, how to do it?(if the name of the trigger is "Bla")

thanks for helping
 
Last edited:
Level 11
Joined
Oct 13, 2005
Messages
233
You can't and don't need to null real values. You only need to null local handles. For a trigger, every time you create a trigger (GUI trigger), the World Editor automatically generates a global variable for it named: "gg_trg_Trigger_Name" (without quotes). In your case, the variable would be "gg_trg_Bla".
 
Level 2
Joined
Jun 5, 2006
Messages
18
You can't and don't need to null real values. You only need to null local handles. For a trigger, every time you create a trigger (GUI trigger), the World Editor automatically generates a global variable for it named: "gg_trg_Trigger_Name" (without quotes). In your case, the variable would be "gg_trg_Bla".

thanks a lot (i've noticed this thing after i post :) i was only looking for the right global :p )

ok ...what exactly type of data is "handle"? is it like a "general" type?
 
Level 11
Joined
Jul 12, 2005
Messages
764
Why do you overcomplicate the function? You don't even need the real variable:

function FDDspellinfoDELAY takes integer i returns real
if i == 0 then
return 2.00
endif
endfunction

Handles include everything that is not a real, integer, boolean, string...umm, what else?
 
Level 2
Joined
Jun 5, 2006
Messages
18
Why do you overcomplicate the function? You don't even need the real variable:

function FDDspellinfoDELAY takes integer i returns real
if i == 0 then
return 2.00
endif
endfunction

Handles include everything that is not a real, integer, boolean, string...umm, what else?

i complicated the function because if i put "return 2.00" (as i've done at the beginning), it sent me an error like "not a real value"(but 2.00 is a real value...bah)...

btw, that was only an example (infact inside the function i've added other things that need that variable :p)....

i'm thinking that it's not too hard to learn the JASS if u are a programmer...expecially because is totally documented (if u don't know the name of a function or parameters that need, reproduce it using GUI and u will have your answer :) )

I've created this function now (that it's runned under an IF that stops the trigger if false)

JASS:
function FDDspellconsumeMANA takes integer i returns boolean
if ( GetUnitStateSwap(UNIT_STATE_MANA, GetTriggerUnit()) < FDDspellinfoMANA(i) ) then
call DisplayTimedTextToForce( GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), 5.00, FDDsyserror(1) )
call PlaySoundBJ( gg_snd_Error )
call TriggerExecute( gg_trg_soundeffect_Delete )
call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" )
return false//Skip Remeaning actions
else
call SetUnitManaBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_MANA, GetTriggerUnit()) - FDDspellinfoMANA(i) ) )
endif
return true
endfunction

a little question: what exactly does call???I've found it in another language (sphere to create uo servers) and this keyword PRESERVES local variables of the "called" function...is the same in warcraft?
 
Last edited:
Level 11
Joined
Jul 20, 2004
Messages
2,760
Why do you overcomplicate the function? You don't even need the real variable:

function FDDspellinfoDELAY takes integer i returns real
if i == 0 then
return 2.00
endif
endfunction

Handles include everything that is not a real, integer, boolean, string...umm, what else?

Ouch, this is wrong. I would be surprised if it actually worked. Why? Because you should know that functions ALWAYS need to return a value. Therefore, for i!=0 you should also return a value (let's say 0.00).

When it comes to nulling a value you want to return, simply make a global variable point to the object, nullify the local, and return the global.

-Daelin
 
Level 11
Joined
Jul 12, 2005
Messages
764
Yeah, yeah, you're right, i forgot it! So this one is correct, isn't it?

function FDDspellinfoDELAY takes integer i returns real
if i == 0 then
return 2.00
endif
return 0.00
endfunction


And Fire-Dragon-DoL, replace non-native functions with native ones. It makes functions run faster. And use JassCraft for coding!
 
Level 2
Joined
Jun 5, 2006
Messages
18
ok guys....that's a good thing to know (usually if a function don't return a value it's not a problem)...but i will put it :p

mh, i prefer write the code with my own hands (at the beginning, u will learn more)

after that..i've corrected everything and now my cast system is working :D

and it's very short (6 lines against more than 20 with GUI)

Btw i use JASS expecially because i can return values with functions (u can't do it with triggers, or u have to use a global...)
 
Status
Not open for further replies.
Top