• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How can i make jass function global?

1730570392154.png

It's not available for some reason
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
How can i make jass function global?
I usually create library.

library MyLib initializer Init requires ...

But if I defined func outside of lib or in lib it is not available unless I require the lib.
Can I make it global somehow so I don't need to bother?
I'm pretty sure the code just needs to be above everything else that uses it. So position your "global" functions at the very top of the trigger editor hierarchy.
 
Last edited:
See i have this RegionLib for example

Code:
library RegionLib requires TextLib

   function GetRandomPointInRect takes rect r returns location
       local real minX = GetRectMinX(r)
       local real minY = GetRectMinY(r)
       local real maxX = GetRectMaxX(r)
       local real maxY = GetRectMaxY(r)
       local real x = minX + GetRandomReal(0, maxX - minX)
       local real y = minY + GetRandomReal(0, maxY - minY)
       return Location(x, y)
   endfunction

function GetRandomPointInCircle takes location center, real radius returns location
   local real angle = GetRandomReal(0, 2 * bj_PI)
   local real distance = GetRandomReal(0, radius)
   local real x = GetLocationX(center) + distance * Cos(angle)
   local real y = GetLocationY(center) + distance * Sin(angle)
   return Location(x, y)
endfunction

endlibrary

can I invoke a global function from lib func somehow?..
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
can I invoke a global function from lib func somehow?..
If what I suggested didn't work, you may need to prefix the function call with the name of your library.

Edit:
It is supposed to be at the top
Not in the header, I mean just position the script above the other scripts. Like how Sun Goes Down is above Morning Sun.
 
If what I suggested didn't work, you may need to prefix the function call with the name of your library.

Edit:

Not in the header, I mean just position the script above the other scripts. Like how Sun Goes Down is above Morning Sun.
Prefix?
 
Level 29
Joined
Sep 26, 2009
Messages
2,595
You will need to wrap your BJ function into another library and make the RegionLib require the new library.
The reason is because in the generated .j file library functions are placed at the top, after them its the map header's script and other scripts.
For example, I've put the 'bj' function into map header and added your RegionLib, this is the generated .j file script:

JASS:
globals
//globals from RegionLib:
constant boolean LIBRARY_RegionLib=true
//endglobals from RegionLib

//JASSHelper struct globals:
endglobals

//library RegionLib:
    function GetRandomPointInRect takes rect r returns location
        local real minX= GetRectMinX(r)
        local real minY= GetRectMinY(r)
        local real maxX= GetRectMaxX(r)
        local real maxY= GetRectMaxY(r)
        local real x= minX + GetRandomReal(0, maxX - minX)
        local real y= minY + GetRandomReal(0, maxY - minY)
        return Location(x, y)
    endfunction
    function GetRandomPointInCircle takes location center,real radius returns location
        local real angle= GetRandomReal(0, 2 * bj_PI)
        local real distance= GetRandomReal(0, radius)
        local real x= GetLocationX(center) + distance * Cos(angle)
        local real y= GetLocationY(center) + distance * Sin(angle)
        return Location(x, y)
    endfunction

//library RegionLib ends
//===========================================================================
//
// Just another Warcraft III map
//
//   Warcraft III map script
//   Generated by the Warcraft III World Editor
//   Map Author: Unknown
//
//===========================================================================
//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

function InitGlobals takes nothing returns nothing
endfunction
//***************************************************************************
//*
//*  Custom Script Code
//*
//***************************************************************************
//***************************************************************************
//*  Untitled Script 001
//***************************************************************************
//*
//*  Unit Creation
//*
//***************************************************************************
//===========================================================================
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p= Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life
    set u=BlzCreateUnitWithSkin(p, 'hfoo', - 378.1, 119.2, 287.708, 'hfoo')
endfunction
//===========================================================================
function CreatePlayerBuildings takes nothing returns nothing
endfunction
//===========================================================================
function CreatePlayerUnits takes nothing returns nothing
    call CreateUnitsForPlayer0()
endfunction
//===========================================================================
function CreateAllUnits takes nothing returns nothing
    call CreatePlayerBuildings()
    call CreateUnitsForPlayer0() // INLINED!!
endfunction
//***************************************************************************
//*
//*  Custom Script Code
//*
//***************************************************************************
function bj takes string msg returns nothing
    call BJDebugMsg(msg)
endfunction
//***************************************************************************
//*
//*  Players
//*
//***************************************************************************
function InitCustomPlayerSlots takes nothing returns nothing
    // Player 0
    call SetPlayerStartLocation(Player(0), 0)
    call SetPlayerColor(Player(0), ConvertPlayerColor(0))
    call SetPlayerRacePreference(Player(0), RACE_PREF_HUMAN)
    call SetPlayerRaceSelectable(Player(0), true)
    call SetPlayerController(Player(0), MAP_CONTROL_USER)
endfunction
function InitCustomTeams takes nothing returns nothing
    // Force: TRIGSTR_002
    call SetPlayerTeam(Player(0), 0)
endfunction
//***************************************************************************
//*
//*  Main Initialization
//*
//***************************************************************************
//===========================================================================
function main takes nothing returns nothing
    call SetCameraBounds(- 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), - 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
    call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
    call NewSoundEnvironment("Default")
    call SetAmbientDaySound("LordaeronSummerDay")
    call SetAmbientNightSound("LordaeronSummerNight")
    call SetMapMusic("Music", true, 0)
    call CreateAllUnits()
    call InitBlizzard()

    call InitGlobals()
endfunction
//***************************************************************************
//*
//*  Map Configuration
//*
//***************************************************************************
function config takes nothing returns nothing
    call SetMapName("Just another Warcraft III map")
    call SetMapDescription("Nondescript")
    call SetPlayers(1)
    call SetTeams(1)
    call SetGamePlacement(MAP_PLACEMENT_USE_MAP_SETTINGS)
    call DefineStartLocation(0, - 384.0, 128.0)
    // Player setup
    call InitCustomPlayerSlots()
    call SetPlayerSlotAvailable(Player(0), MAP_CONTROL_USER)
    call InitGenericPlayerSlots()
endfunction



//Struct method generated initializers/callers:

Notice that the 'bj' function is placed lower than functions from RegionLib.
The rule is that you can only call functions that are placed earlier in the script - because the bj function is placed below, it cannot be called and you get an error.

Edit: Basically -
JASS:
function A takes nothing returns nothing
   // some code here
endfunction

function B takes nothing returns nothing
   // some code here
endfunction
Function B can call A, because A is placed earlier in the script. Function A will not be able to call B, because it is placed later/below in the script.
 
Top