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

I just Installed vJass and...

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Tried to convert my trigger into it. It doesn't compile because of "gg_rct", globals from another trigger, udg_UDex_Enabled and stuff like that. Help? Undeclared variables in short.

JASS:
globals
    string array PlayerColor
    string array CityName
    unit array City
    integer array CityType
    unit array CityController
    
    
endglobals

function Setup takes nothing returns boolean
    local rect array citySpawn
    local integer i
    local integer j
    local player p
    local unit u
    local real x
    local real y
    local boolean b1
    local boolean b2
    
    set udg_UDexEnabled = false 
    
    // Harvest Setup
    
    set RESOURCE_STRING[0] = "Silver"
    set RESOURCE_STRING[1] = "Copper"
    set RESOURCE_STRING[2] = "Lumber"
    set RESOURCE_STRING[3] = "Wheat" 
    set RESOURCE_STRING[4] = "Weaponry"
    set RESOURCE_TYPE[0] = 'n00K'   
    set RESOURCE_TYPE[1] = 'n00E'
    set RESOURCE_TYPE[2] = 'n00H'
    set RESOURCE_TYPE[3] = 'n00F'
    set i = 0
    loop
        exitwhen RESOURCE_TYPE[i] == null 
        set RESOURCE_MINING_TIME[i] = 10
        set RESOURCE_PER_HIT[i] = 1
        set i = i + 1
    endloop
    set RESOURCE_MAX_CARRY_WORKER = 10 
    
    // City Setup
    
    set CityName[0] =  "Sparta"
    set CityName[1] =  "Athens"
    set CityName[2] =  "Larissa"
    set CityName[3] =  "Thebes"
    
    set citySpawn[0] = gg_rct_CITY000
    set citySpawn[1] = gg_rct_CITY001
    set citySpawn[2] = gg_rct_CITY002
    set citySpawn[3] = gg_rct_CITY003
    
    set CityType[0] = 'htow' 
    
    set i = 0
    set p = Player(0) //PLAYER_NEUTRAL_AGGRESSIVE 
    if (udg_UDexEnabled == false) then 
        loop
            exitwhen citySpawn[i] == null
            set x = GetLocationX(GetRectCenter(citySpawn[i]))
            set y = GetLocationY(GetRectCenter(citySpawn[i]))
            set City[i] = CreateUnit(p, CityType[0], x, y, 0)
            call RemoveRect(citySpawn[i])
            set i = i + 1
        endloop
    endif
    
    // Faction Setup 
    
    // Player Setup 
    set b1 = false          // Remove Computers
    set j = 'hpea'          // Controller Unit Type
    set i = 0
    loop
        exitwhen i > 11
        if (udg_UDexEnabled == false) then
            if (GetPlayerSlotState(Player(i)) != PLAYER_SLOT_STATE_EMPTY and GetPlayerController(Player(i)) != MAP_CONTROL_COMPUTER ) then
                set CityController[i] = CreateUnit(Player(i), j, 0, 0, 0) 
                call ShowUnit(u, false) 
            elseif (GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER and b1 == false) then
                set CityController[i] = CreateUnit(Player(i), j, 0, 0, 0) 
                call ShowUnit(u, false)   
            endif
        endif
    endloop
    
    
    set u = null
    set p = null
    
    return false 
endfunction

//===========================================================================
function InitTrig_Main_Setup takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, Condition( function Setup  ) )
    call DestroyTrigger(t)
    set t = null
endfunction

JASS:
globals

    

    string array RESOURCE_STRING
    integer array RESOURCE_TYPE
    integer array RESOURCE_MINING_TIME
    integer array RESOURCE_MAX_CARRY_WORKER
    integer array RESOURCE_MAX_CARRY_CARAVAN
    integer array RESOURCE_PER_HIT
    
    integer array ResourcePlayer
    integer array ResourceCity
    
    integer array WorkerGetHome
    integer array WorkerGetWork
    boolean array WorkerMining
endglobals
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,337
Alright, so there's a few important things to fix.

First off, all vJASS code/triggers always need(s) to be in a library or scope. If it's not in any of those, the code won't compile (AFAIK) and you'll get an error.
Second of all, your InitTrig_Main_Setup function is done wrong.

JASS:
function InitTrig_Main_Setup takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, Condition( function Setup  ) )
    call DestroyTrigger(t)
    set t = null
endfunction


InitTrig_Main_Setup

The name is way too long (a style thing), and also triggers aren't used to initialize values generally.

Third, your trigger has no event, so the function Setup will never fire.

call DestroyTrigger(t)

And fourth, you destroy your trigger right after setting it up. Which means if the trigger did have an event, it would never fire (because it got removed immediately!).

With those things in mind, I'll try to provide a template for doing your initialization libraries.

JASS:
library yourLibraryName initializer init
//init is the name of the function your library
//it will be called on map initialization
//note it can be named anything, as long as the names match up

//you did the globals block correctly
globals
  …
  private timer t
endglobals

//now there are two options when doing an init
//you can do all your stuff inside the function
//or use a timer that calls another function
//timer is a safer option if you are doing stuff with dialogs

//our main function
//this is basically your Setup function
//note we use the private keyword in case you
//have multiple libraries and wish to use the same function names
private function main takes nothing returns nothing
  //your code here
  …
  //last line should destroy the timer
  call DestroyTimer(t)
  set t = null
endfunction

//now our init function
private function init takes nothing returns nothing
  set t = CreateTimer()
  call TimerStart(t, 0.10, false, function main)
endfunction

endlibrary

It doesn't compile because of "gg_rct"

"gg" is the prefix used on all pre-placed variables made in the editor--these include regions/rects, pre-placed units, buildings, doodads, destructables, etc.

You don't need to use the prefix. Instead I recommend simply making your rects in the Setup/main function. Just draw the rect in the editor, then copy the coordinates into the Rect creation function. Then delete the rect in the editor.

Note that the editor rects go left right bottom top. The Rect constructor however expects it like this: Rect(left, bottom, right, top)

JASS:
private function main takes nothing returns nothing
  set citySpawn[0] = Rect(left, bottom, right, top)
  …
endfunction

globals from another trigger

To get/invoke these, you need to either move all those globals into the same library as your initialization, or use the requires keyword, and have a separate library for your other globals. Here's what it would look like.

JASS:
library myConstants

globals

    

    string array RESOURCE_STRING
    integer array RESOURCE_TYPE
    integer array RESOURCE_MINING_TIME
    integer array RESOURCE_MAX_CARRY_WORKER
    integer array RESOURCE_MAX_CARRY_CARAVAN
    integer array RESOURCE_PER_HIT
    
    integer array ResourcePlayer
    integer array ResourceCity
    
    integer array WorkerGetHome
    integer array WorkerGetWork
    boolean array WorkerMining
endglobals

endlibrary

Now simply use "requires" to invoke those global variables.

JASS:
library Setup initializer init requires myConstants

//rest of your code here (from the first JASS script).  
…

endlibrary

Try these changes, and also look at scripts in the Hive. To help I also provided one of my own libraries that initializes values for you to compare to (it should compile and work).

JASS:
library RectConstants initializer init

globals
	private timer t
	rect AGON_RECT
	rect PLAY_RECT
	rect SUNCHAMBER_BOSS_RECT
	rect SUNCHAMBER_CENTER_RECT
	rect SUNCHAMBER_MIRROR_A_RECT
	rect SUNCHAMBER_MIRROR_B_RECT
	rect SUNCHAMBER_MIRROR_C_RECT
	rect SUNCHAMBER_MIRROR_D_RECT
endglobals

private function main takes nothing returns nothing
	set AGON_RECT = Rect(-4784, -3712, -1664, 7392)
	//set AGON_RECT = Rect(-13440, 9184, -11744, 10688)
	set PLAY_RECT = Rect(-13440, 9184, -11744, 10688)
	set SUNCHAMBER_MIRROR_A_RECT = Rect(10400, 11552, 10784, 11904)
	set SUNCHAMBER_MIRROR_B_RECT = Rect(12320, 11584, 12672, 11904)
	set SUNCHAMBER_MIRROR_C_RECT = Rect(10464, 10240, 10816, 10528)
	set SUNCHAMBER_MIRROR_D_RECT = Rect(12256, 10304, 12608, 10656)
	set SUNCHAMBER_BOSS_RECT = Rect(10016, 10176, 12704, 12096)
	set SUNCHAMBER_CENTER_RECT = Rect(11232, 10848, 11904, 11264)
	call DestroyTimer(t)
	set t = null
endfunction

private function init takes nothing returns nothing
    set t = CreateTimer()
    call TimerStart(t, 0.50, false, function main)
endfunction

endlibrary
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
library MainSetup initializer init 

globals 
    string array s 
    private timer t
endglobals

private function main takes nothing returns nothing
    local integer i = 0
    loop 
        exitwhen i > 5
        set s[i] = I2S(i)
        call BJDebugMsg(s[i])
        set i = i + 1
    endloop
    
    call PauseTimer(t) 
    call DestroyTimer(t) 
    set t = null
    call SetupBuildings()
    call BJDebugMsg("Working...") 
    call BJDebugMsg(b)
    
    //call SetupBuildings()
endfunction

//===========================================================================
private function init takes nothing returns nothing
    set t = CreateTimer()
    call TimerStart(t, 0.10, false, function main)
    set s[6] = "Hello"
    call BJDebugMsg(s[6])
endfunction

endlibrary
How about throwing it into a trigger?

JASS:
library OrderConstruction initializer init

globals
    integer array CityBuilding_order
    integer array CityBuilding_type
endglobals

private function Construction takes nothing returns boolean
    
    // Do stuff!

    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_ORDER) 
    call TriggerAddCondition(t, Condition(function Construction)) 
    set t = null 

    // Barracks
    set CityBuilding_type[0] = 'hbar'
    set CityBuilding_order[0] = String2OrderIdBJ("humanbarracks")
    // Farm
    set CityBuilding_type[1] = 'hhou'
    set CityBuilding_order[1] = String2OrderIdBJ("farm")
    // Stable
    set CityBuilding_type[2] = 'hgra'
    set CityBuilding_order[2] = String2OrderIdBJ("gryphonaviary")
    // Archery Range
    set CityBuilding_type[3] = 'harm'
    set CityBuilding_order[3] = String2OrderIdBJ("workshop")
    // House
    set CityBuilding_type[4] = 'nefm'
    set CityBuilding_order[4] = String2OrderIdBJ("elvenfarm")
    // Shipyard
    set CityBuilding_type[5] = 'hshy'
    set CityBuilding_order[5] = String2OrderIdBJ("humanshipyard")
    // Granary
    set CityBuilding_type[6] = 'nitb'
    set CityBuilding_order[6] = String2OrderIdBJ("treasurebox")
    // Blacksmith
    set CityBuilding_type[7] = 'hbla'
    set CityBuilding_order[7] = String2OrderIdBJ("blacksmith")
    // Well
    set CityBuilding_type[8] = 'nmgv'
    set CityBuilding_order[8] = String2OrderIdBJ("magicvault")
    // Market
    set CityBuilding_type[9] = 'nfrt'
    set CityBuilding_order[9] = String2OrderIdBJ("fruitstand")
    // Estate
    set CityBuilding_type[10] = 'hvlt'
    set CityBuilding_order[10] = String2OrderIdBJ("arcanevault")
    // Temple
    set CityBuilding_type[11] = 'halt'
    set CityBuilding_order[11] = String2OrderIdBJ("altarofkings")
    // Academy
    set CityBuilding_type[12] = 'hars'
    set CityBuilding_order[12] = String2OrderIdBJ("arcanesanctum")
    // Garrison
    set CityBuilding_type[13] = 'obea'
    set CityBuilding_order[13] = String2OrderIdBJ("beastiary") 
    
endfunction

endlibrary
 
Last edited:
Status
Not open for further replies.
Top