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

[JASS] globals block syntax error

Status
Not open for further replies.
Level 1
Joined
Oct 31, 2017
Messages
4
Hiho,

I get syntax errors on these lines of simple globals declaration:


I know in vanilla editor there can only be one globals block, but I'm using WEX and I thought it somehow merges it to the precompiler.

Is there a way I don't have to use the variables-editor from WE? Maybe disabling the syntax check(how? :D)

Thanks in advance,

Beer

EDIT: Also is there a way to init a unit array in a loop by increment the unit ID +1?
like:
Code:
local integer index = 1
local integer unit_id = 1
loop
set udg_units[index] = unit_id
set index = index+1
set unit_id = unit_id+1
exitwhen index = 10
endloop

or something?
 
Last edited:
In your function, did you just try to declare a globals section, like this?

JASS:
function InitTrig_Globals_Actions takes nothing returns nothing
    globals
        integer a
    endglobals
endfunction

If using vJASS, move globals outside of functions.

As for your second question, you have already resolved it. The only problematic part is this:

JASS:
exitwhen index = 10   // Should be exitwhen index == 10
 
Level 1
Joined
Oct 31, 2017
Messages
4
Okay i moved the globals block outside the function (makes sense) like this:
JASS:
globals
   integer a = 0
endglobals


function Trig_Init_Units_Actions takes nothing returns nothing
//mycode
endfunction
//===========================================================================
function InitTrig_Init_Units takes nothing returns nothing
    set gg_trg_Init_Units = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Init_Units, function Trig_Init_Units_Actions )
endfunction

But it still doesn't let me activate the trigger, saying 'unknown compileerror (systax error)' on this line:
JASS:
globals

vJass is enabled btw.

My guess is that I just have to deactivate the "vanilla syntax checker" but I could not find that option anywhere.
 
Level 13
Joined
Nov 7, 2014
Messages
571
In your function, did you just try to declare a globals section, like this?
JASS:
function InitTrig_Globals_Actions takes nothing returns nothing
    globals
        integer a
    endglobals
endfunction
If using vJASS, move globals outside of functions.

vJass does allow putting globals blocks anywhere (or at least in the global scope and function bodies, kind of like textmacros).
JASS:
// vJass would gather all the globals blocks, no mater where they are, and merge them into 1
function foo takes nothing returns nothing
globals
    integer bar = 4
endglobals
    call BJDebugMsg(I2S(bar))
endfunction

In fact, this is how cJass implements its static variables, it simply puts them in a globals/endglobals block (also renaming them to be unique) and lets vJass do all the "heavy lifting".
 
Level 18
Joined
Nov 21, 2012
Messages
835
check your settings under "compilers" tag
compilers.jpg
 
Status
Not open for further replies.
Top