Warcraft III resources & community, 2003–2006 · archived

Arguments?

11 posts
#1

Arguments?

After a LONG time being absorbed by WoW i have decided to come back to modding Wc3, and along with that, learn JASS as well. Im not familiar with the scripting language, but i do understand variables and whatnot, as i am in the process of learing C++ as well.

Im making this thing that using JASS tells the owner of a dying unit that the unit has died and what type of unit it is.

e.g. When a sorceress owned by player red dies the game tell red: "Your unit, a SORCERESS, has died."

But when i try to do the script it errors and disables and a couple of the 3 reasons are "invalid number of arguments". I try to fix these, but Nomatter what i cant get it to work.

So my question is: What is an argument and what does it mean that there are an ivalid number of them?

P.S., If you need the code, i can give it to you. Its not complete but there is enough in it for it to run in a basic form, IF i could fix the argument problem.

Thanks,
With Regards,
AlphaChicken
#2
allright... arguments, AKA parameters.

lets say we take CreateUnit.

native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit


(player id) is an argument

in this case, its asking for a player.

(integer unitid) is ALSO an argument. it wants an integer.

now, unlike most languages, JASS has no optional arguments (parameters), so you have to use every single one.

for example, if i was to say

[...]
    call CreateUnit(Player(1), 'h000', 1000, 1000)


it would give me an Invalid Number of Arguments, as im missing the 5th argument (the facing).

so, also, arguments must follow the right TYPE.

if i type in

[...]
    call CreateUnit(Player(cheese), 'h000', 1000, 1000, 360)


i will get an Invalid Argument or something, as cheese is not an integer, unless i made it an integer variable.

hope this helped :D
#3
awesome, so im missing a parentheses group. let me post my script and see if you can tell me whats wrong with the script.



function Trig_Unit_Dies_Message_Conditions takes nothing returns boolean
    if ( not ( IsUnitType ( GetTriggerUnit (), UNIT_TYPE_HERO ) == false ) ) then
        return false
        endif    
    return true
endfunction

function Trig_Unit_Dies_Message_Actions takes nothing returns nothing
    local string a=GetDyingUnit()
    
    
    call DisplayTextToForce ( GetOwningPlayer( GetTriggerUnit() ), a  )
    endfunction
    

function InitTrig_Unit_Dies_Message takes nothing returns nothing
    
    set gg_trg_Unit_Dies_Message = CreateTrigger()
    
    call TriggerRegisterUnitEvent (gg_trg_Unit_Dies_Message, EVENT_PLAYER_UNIT_DEATH )

    call TriggerAddCondition ( gg_trg_Unit_Dies_Message, Condition( Trig_Unit_Dies_Message_Conditions ) ) 
    
    call TriggerAddAction(gg_trg_Unit_Dies_Message, function Trig_Unit_Dies_Message_Actions)
    
endfunction


thanks a ton.
#4
First, local string a = GetDyingUnit() wont work. I think there may be a GetUnitName function, but you cannot cast variables in JASS.

anyways, few more things.

Posted: Thu Oct 19, 2006 6:16 pm Post subject:


function Trig_Unit_Dies_Message_Conditions takes nothing returns boolean 
if ( not ( IsUnitType ( GetTriggerUnit (), UNIT_TYPE_HERO ) == false ) ) then 
return false 
endif 
return true
endfunction


This is stupid. I dont blame you for using it, but the code is completely unnecesary, and its something everyone needs to be told how to fix sometime :D.

all that can be replaced with...

function Trig_Unit_Dies_Message_Conditions takes nothing returns boolean 
    return not IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO)
endfunction


Next, and last, the way you use DisplayTextToForce suggests it looks like this

function DisplayTextToForce takes player toPlayer, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, message)
    endif
endfunction


whereas it really looks like this.

function DisplayTextToForce takes force toForce, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, message)
    endif
endfunction


meaning you have to supply a force, not a player ( again, you cannot cast in JASS, variables are super-picky. )

finally, the function that you SHOULD be using with those parameters is

native DisplayTextToPlayer takes player toPlayer, real x, real y, string message returns nothing


note - for normal positioning, use 0 for x and y, meaning you would write

call DisplayTextToPlayer( GetOwningPlayer( GetTriggerUnit() ), 0, 0, a )
#5
ok awesome. I thought that i coudnt use the gettrigger unit thing. wasnt sure what else to use though. thanks a ton!
#6
:shock: handy... check it out!

constant native GetUnitName takes unit whichUnit returns string


meaning that

local string a=GetDyingUnit()


should be removed, and instead,

call DisplayTextToForce( GetOwningPlayer( GetTriggerUnit() ), a )


can be changed to

call DisplayTextToForce( GetOwningPlayer( GetTriggerUnit() ), GetUnitName( GetTriggerUnit() ) )
#7
awesome very nice. tyvm for your help :-D
#8
ugh... im an idiot, CnPed that text line from your code, not mine...

(should be DisplayTextToPlayer)

anyways, np, nice to see someone else taking the time to learn JASS :D
#9
C++? Can you tell me a good (and free) editor?
Something simple like JavaEditor - just for C++.

A compiler would also be nice. ^^
#10
AlphaChicken just create GUI trigger next time, convert it to jass, and look athow you're supposed to write it.

LordZsar1
Programmer's Notepad2 for editing.
gcc for compiling.
#11
must you flame everyone that tries to learn?