• 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] Arguments?

Status
Not open for further replies.
Level 5
Joined
Jun 18, 2004
Messages
136
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
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
allright... arguments, AKA parameters.

lets say we take CreateUnit.

JASS:
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

JASS:
[...]
    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

JASS:
[...]
    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
 
Level 5
Joined
Jun 18, 2004
Messages
136
awesome, so im missing a parentheses group. let me post my script and see if you can tell me whats wrong with the script.


JASS:
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.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
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:

JASS:
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...
JASS:
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

JASS:
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.

JASS:
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

JASS:
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

JASS:
call DisplayTextToPlayer( GetOwningPlayer( GetTriggerUnit() ), 0, 0, a )
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
:shock: handy... check it out!

JASS:
constant native GetUnitName takes unit whichUnit returns string

meaning that

JASS:
local string a=GetDyingUnit()

should be removed, and instead,

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

can be changed to

JASS:
call DisplayTextToForce( GetOwningPlayer( GetTriggerUnit() ), GetUnitName( GetTriggerUnit() ) )
 
Level 5
Joined
May 22, 2006
Messages
150
C++? Can you tell me a good (and free) editor?
Something simple like JavaEditor - just for C++.

A compiler would also be nice. ^^
 
Status
Not open for further replies.
Top