• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Why I get an "Expected a Name" error

Status
Not open for further replies.
Level 4
Joined
Feb 16, 2017
Messages
53
Hello ,I'm not very familiar with this forum, and I just started to learn JASS,
I'm constantly getting this error, for example: how do I fix this error
Code:
function Heal takes nothing returns nothing
    // this example will heal all units in a unit group.
    local unit u
    loop
        set u = FirstOfGroup(udg_g) //Selects the first unit in the group.
       
        exitwhen u == null
       
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE))
       
        call GroupRemoveUnit(udg_g, u) // removes the unit from the group
    endloop
    call DestroyGroup(udg_g) // to avoid group leaks, we must destroy the group variable.
endfunction

Code:
call Heal(udg_g)
 
Level 7
Joined
Apr 17, 2017
Messages
316
If you want to use a function with parenthesis it must take something. In this case it should be like this.If you don't want to change it you can still call that function like call Heal()
JASS:
function Heal takes group g returns nothing
local unit u

set u = FirstOfGroup(g)
loop 
exitwhen u == null

call SetUnitState(u, UNIT_STATE_LIFE,  GetUnitState(u, UNIT_STATE_MAX_LIFE))


call GroupRemoveUnit(g, u,)

endloop

call DestroyGroup(g)
endfunction
On my phone so apologies for no proper indentation
 
Level 8
Joined
Oct 4, 2016
Messages
208
Your function not takes any parameter, but when you call it, gives the group.
You only need to call the function without the group.
call Heal()
And the group its a global variable no need to pass to the function as a parameter.
You can access any global variable in any function.

Regards.
 
Level 4
Joined
Feb 16, 2017
Messages
53
Your function not takes any parameter, but when you call it, gives the group.
You only need to call the function without the group.
call Heal()
And the group its a global variable no need to pass to the function as a parameter.
You can access any global variable in any function.

Regards.
 

Attachments

  • 1.png
    1.png
    58.2 KB · Views: 56
  • 2.png
    2.png
    73.7 KB · Views: 34
Level 4
Joined
Feb 16, 2017
Messages
53
If you want to use a function with parenthesis it must take something. In this case it should be like this.If you don't want to change it you can still call that function like call Heal()
JASS:
function Heal takes group g returns nothing
local unit u

set u = FirstOfGroup(g)
loop
exitwhen u == null

call SetUnitState(u, UNIT_STATE_LIFE,  GetUnitState(u, UNIT_STATE_MAX_LIFE))


call GroupRemoveUnit(g, u,)

endloop

call DestroyGroup(g)
endfunction
On my phone so apologies for no proper indentation

Code:
function Heal takes group g returns nothing
local unit u

set u = FirstOfGroup(g)
loop
exitwhen u == null

call SetUnitState(u, UNIT_STATE_LIFE,  GetUnitState(u, UNIT_STATE_MAX_LIFE))


call GroupRemoveUnit(g, u,)

endloop

call DestroyGroup(g)
endfunction

Code:
call Heal(udg_g)

Code:
call Heal(g)

I try all , but getting error
 
Status
Not open for further replies.
Top