• 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 communicate between zinc and jass scripts?

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
I have one script written in zinc that detects when a player dies. And the other written in jass that updates the multiboard. How can I create a boolean that changes when a player dies and have the jass script check if the boolean = true or false and run code?
 
Level 13
Joined
May 10, 2009
Messages
868
Well, if you were to solely use ZINC in your entire map, then making a function or variable private means they can only be accessed within the library they were declared.

If you mix JASS with Zinc, you can still access the Zinc private functions and variables, however they get a HUGE name, and their prefix is randomly generated.

I guess there's no problem declaring the variable in JASS, and using it in ZINC snippets, that way you have more control over them. Otherwise, you'll need to check the war3map.j (by intentionally inserting gibberish into the map script, and forcing the editor to throw an error), and see how the variable has been defined.

EDIT: Example
JASS:
//! zinc
library PlayerStatus
{
    public boolean playerDead[12];

    function PlayerStatusDeath() -> boolean
    {
        playerDead[GetPlayerId(GetTriggerPlayer())] = true;
        return true;
    }
 
    function onInit()
    {
        integer i = 0;
        trigger t = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH);
        TriggerAddCondition(t, Condition(function PlayerStatusDeath));
  
        for(0 <= i <= 11)
        {
            playerDead[i] = false;
        }
    }
}
//! endzinc

and then

upload_2018-5-15_13-25-22.png


If you remove the "public" keyword when declaring the variable, it becomes private by default, and its name size increases.
upload_2018-5-15_13-28-48.png


EDIT 2: Apparently, I forgot to mention that I got that "s__" prefix by declaring a sized array. public boolean playerDead[12];

Declaring it normally public boolean playerDead[]; does not add that "s__". So take into account what IcemanBo said below.
 
Last edited:
Level 12
Joined
Mar 24, 2011
Messages
1,082
I think I tried it in the jass script, I created a private global and tried to access it in the zinc script and it said variable undefined. I'm still a little fuzzy on what private means, does that mean it's confined to only the one script?
"Private" in most programming languages & scripts means that it cannot be accessed from outside.
 
Level 12
Joined
Dec 2, 2016
Messages
733
I've got this in my jass script,

JASS:
globals
  public boolean isDead = false
endglobals


and

JASS:
isDead = true;

in my zinc script, it's inside a function. It errors saying isDead is not declared. I'm not sure what's wrong?
Do I need to do library requires (script the jass is in) ?
 
"Public" can only be used inside a scope or library and requires you to name the code scope of definition of the variable. For example if it's in library A, then:

JASS:
library A
    globals
        public boolean isDead = false
    endglobals
endlibrary

you would need to reference it with A_isDead. Private means you can not reference it from outside, and without any access prefix, so only boolean isDead = false, then you would not need the library's name at front, and could simply use it like you already do.

Do I need to do library requires (script the jass is in) ?
If one library needs to use an other library then yes:

JASS:
library A requires B
endlibrary
^if B has variables that A should use. JassHelper 0.A.0.0
 
Status
Not open for further replies.
Top