• 🏆 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!

[JASS] New to JASS, GetUnitsInRangeOfLocMatching

Status
Not open for further replies.
Level 12
Joined
Mar 24, 2011
Messages
1,082
Greetings

Earlier, after getting annoyed with GUI/JASS I decided to switch to JASS full-time... So, I converted part of my trigger to JASS and decided to write the rest myself... if it was a success I would not be starting this thread, would I ?

So I have this thing which gives me the annoying error of "Expected a function name":
JASS:
set udg_TempUnitGroup = GetUnitsInRangeOfLocMatching(udg_SVA_Range, udg_TempPoint, Condition(function CheckForAbility))
I am pretty sure that it is correct because it is just a converted GUI line with custom function name and I searched and looked through... a lot of threads and spells around to see if the syntax is wrong... so any suggestions ?


JASS:
function EnumGroup takes nothing returns nothing
local integer array LevelMax
set udg_TempUnitGroup = GetUnitsInRangeOfLocMatching(udg_SVA_Range, udg_TempPoint, Condition(function CheckForAbility))
set udg_TempInt = CountUnitsInGroup(udg_TempUnitGroup)
set udg_TempPoint = GetUnitLoc(udg_PDD_source)
set udg_TempLoopIndex = 0


endfunction

function CheckForAbility takes nothing returns boolean
    return ( GetUnitAbilityLevelSwapped('A002', GetFilterUnit()) > 0 )
endfunction
JASS:
function Trig_SVADetection_Actions takes nothing returns nothing
    if ( Trig_SVADetection_Func001C() ) then
        call EnumGroup()
    else
    endif
endfunction

PS: I take suggestions and criticism about improving the code as I am not knowledgeable of JASS at all...
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
JASS works pretty simple.

1. All GUI triggers are converted to JASS (same as "Convert to Custom Text").
2. All JASS triggers are combined into one massive file (similar to the header file but in the header you cannot have those InitTrig_ functions)
3. JASS reads through the whole code and creates everything.
When it creates everything, it does exacly as it says.
It creates a new function "EnumGroup"
It gives it a local variable "integer array LevelMax"
It sets a unit group... wait... what is "CheckForAbility"? I have never heard of it before.
I quit.

All things that have to be used by others must be declared before they are used.
Sometimes you cannot put the other one before the first...
JASS:
function f1 takes nothing returns nothing
    call f2()
endfunction

function f2 takes nothing returns nothing
    call f1()
endfunction
In that case you should save them in global variables and run the variables instead.

(Personally I would do it different. I would loop through the file multiple times.
First time to make objects (structs). Second time to make global variables. Third time to make functions. Fourth time to fill the functions. (maybe some more but that is all I can think of)
But that would be something for WC4)
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
CheckForAbility has to be placed above its first use, so above the EnumGroup function.

I must be pretty blind to miss that... Sooooo to my previous statement, enough hive/war3 for today... goining to play something, after that to sleep...


So... basically I am using a function before initializing it... I do not know how I missed that... or why I wrote it after its parent... maybe I am thinking in c#...

@Wietlol
The whole thing started with me wanting local variables and trying to avoid globals to some extend...
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
JASS works pretty simple.

1. All GUI triggers are converted to JASS (same as "Convert to Custom Text").
2. All JASS triggers are combined into one massive file (similar to the header file but in the header you cannot have those InitTrig_ functions)
3. JASS reads through the whole code and creates everything.
When it creates everything, it does exacly as it says.
It creates a new function "EnumGroup"
It gives it a local variable "integer array LevelMax"
It sets a unit group... wait... what is "CheckForAbility"? I have never heard of it before.
I quit.

All things that have to be used by others must be declared before they are used.
Sometimes you cannot put the other one before the first...
JASS:
function f1 takes nothing returns nothing
    call f2()
endfunction

function f2 takes nothing returns nothing
    call f1()
endfunction
In that case you should save them in global variables and run the variables instead.

(Personally I would do it different. I would loop through the file multiple times.
First time to make objects (structs). Second time to make global variables. Third time to make functions. Fourth time to fill the functions. (maybe some more but that is all I can think of)
But that would be something for WC4)

I will be nitpicky here.

Jass is language, it does nothing on itself.

The syntax cheker built into warcraft 3, or if you use JNGP then JassHelper is the one responsible for checking the code for validity. Jass is made in C/C++ way, so you have to declare everything before its first use.

JassHelper could easily violate this rule(it seemingly does, but not in reality), but the problem here is that before you start the map from editor, or as wc3 loads maps when he is about to display them in list ingame, he will do syntax check on the map, and if the syntax is not correct, it will not let you open that map.

Also pure Jass knows only about: function, local, globals, native, type, loop, if, and vJass allows you to fake polymorphism and goodies like it allows
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Jass is language, it does nothing on itself.
Why you have to be so mean :(

Also pure Jass knows only about: function, local, globals, native, type, loop, if, and vJass allows you to fake polymorphism and goodies like it allows
Yea but I said "if I would make it".
I would also make objects and stuff.
I know that this is technically impossible because C is not an OO language but even then... it would be so much better if the possibilities were endless in WC Editor.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
how is C related to Jass?

Also as JassHelper by Vexorian, and later modifications of Cohadar's prove you can seemingly have user-defined types, and you can have real user defined types too.

JASS:
type t extends unit

is valid Jass, and it will compile in normal editor, but you can not instantiate t because there is no native creating it
 
Status
Not open for further replies.
Top