• 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] "must not take any arguments when used as code"

Status
Not open for further replies.
Level 18
Joined
Sep 2, 2005
Messages
1,029
How do I get around this? I want to call a function from a ForGroupBJ(). There are 2 different scenarios, and one of them will need a variable integer passed to it. What do I do?

Code Snippet
JASS:
      if (remainder < 0) then
        set remainder = remainder/allCount
        if (remainder<1) then
        call ForGroupBJ(all, function DeincrementLife(1))
        else
        call ForGroupBJ(all, function DeincrementLife(remainder))
        endif
      endif
 
Level 18
Joined
Sep 2, 2005
Messages
1,029
store it in a global, call ForGroup, and use the global in the callback. Also, don't use ForGroupBJ... use:
JASS:
native ForGroup takes group whichGroup, code callback returns nothing

I'm actually not sure how to make a global in Jass. I've done it with the menu in GUI before though. How DO I declare a global in jass?
 
Last edited:
Level 12
Joined
Aug 20, 2007
Messages
866
Same way

Just in Jass, you must refer to them with "udg_" in front of them, which stands for "User Defined Global", because wc already generates it's own globals, but it needs to differentiate between them in the code (like when you create a trigger then convert it, there is a generated trigger global)
 
Level 11
Joined
Feb 18, 2004
Messages
394
you really should just use the JASS NewGen editor so you can define your own globals. Get it here: http://wc3campaigns.net/showthread.php?t=90999

Then you define globals in globals blocks:
JASS:
globals
    [constant] <type> <name> [= <default value>] // The basic syntax
    unit MyUnit // a valid example
    integer MyInt = 34
    constant integer THIS_VAR_CAN_NOT_BE_SET = 34523
endglobals
You can define as many or as few as you want in as many global blocks as you want. Where a block of globals is in the maps script doesn't matter, you can use them anywhere. constant globals can not have their values changed. Do not initialize globals using functions. Eg, this will crash WC3:
JASS:
globals
    unit u = CreateUnit(...)
endglobals
 
Level 9
Joined
Mar 25, 2005
Messages
252
In this case you could use bj_forLoopAIndex for example (so you don't need to declare your own globals)
Example:
JASS:
function DeincrementLife takes nothing returns nothing
    call SetUnitState(GetEnumUnit(), UNIT_STATE_LIFE, GetWidgetLife(GetEnumUnit())-bj_forLoopAIndex)
endfunction
//......
      if (remainder < 0) then
        set remainder = remainder/allCount
        if (remainder<1) then
        set bj_forLoopAIndex = 1
        call ForGroup(all, function DeincrementLife)
        else
        set bj_forLoopAIndex = remainder
        call ForGroup(all, function DeincrementLife)
        endif
      endif
 
Status
Not open for further replies.
Top