[JASS] Setting Global Variables

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hello :thumbs_up:

I am learning JASS and it is cool now that I can sort of understand it! Just one question: how do I set global variables properly? I know you do this in the trigger editor, by setting the normal ones, but in JASSCraft it says "undeclared variable". I then put this at the beginning of my script:

JASS:
globals
    unit udg_Hero
    integer udg_Deaths
endglobals
JASSCraft accepts this, but World Editor says "Expected end of line" for each of these lines. What is the problem?

+Rep for any help! :wink:
Thanks,
 
If you are using variables from GUI variable editor, they are already declared with map script, you do not need to do it manually - if you do, the "Expected end of line" error will appear.

If you gonna move to vJass, declaring globals looks somewhat like your script:
JASS:
globals
    unit Hero = null
    integer Deaths = 0
endglobals
With NewGen variable editor becomes pretty useless. Remember to set initial value to non array global variables.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
In plain Jass, there can only be one globals-block and is declared on top before any functions. The World Editor does not give you direct access to the block, so only generated variables and from the GUI variable editor can be implemented. When using JNGP and vJass is enabled, global-blocks can be spread throughout the code and get automatically merged to the top block by the precompiler.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Jass regions or the rects from GUI?

Jass regions:
1. What is the center here?
2. You would need to keep track of the added cells, choose a random one of these and add a random offset between 0 and 32. At least, this would be some bruteforce solution.

GUI rects:
1. MoveLocation(<location>, GetRectCenterX(<rect>), GetRectCenterY(<rect>))
2. MoveLocation(<location>, GetRandomReal(GetRectMinX(<rect>), GetRectMaxX(<rect>)), GetRandomReal(GetRectMinY(<rect>), GetRectMaxY(<rect>)))
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Region.jpg


I want to (using JASS):
1. Create a unit in the center of this region.
2. Create a unit at a random location in this region.

How would I do this?
 
JASS:
function random takes nothing returns nothing
    local real x = GetRandomReal(GetRectMinX(<rect>), GetRectMaxX(<rect>)
    local real y = GetRandomReal(GetRectMinY(<rect>), GetRectMaxY(<rect>)
    set bj_lastCreatedUnit = CreateUnit(Player(0), 'unitid', x, y, bj_UNIT_FACING)
endfunction

function center takes nothing returns nothing
    local real x = GetRectCenterX(<rect>)
    local real y = GetRectCenterY(<rect>)
    set bj_lastCreatedUnit = CreateUnit(Player(0), 'unitid', x, y, bj_UNIT_FACING)
endfunction
 
Status
Not open for further replies.
Top