Because it is good for your brains
Zinc is good for your brain's development. Likewise, the Zinc scripting language is good for ...your code development. So let's see some examples of code...
Hello world
For better or worse, Zinc is completely library-based. So we begin by declaring a Hello World library. Unlike vJass, there is no need to explicitly declare an initializer function name, and the function called onInit will be used directly (if it exists), The function has no arguments, and no return value. It simply calls a jass function BJDebugMsg
to do the text display.
99 bottles of beer
This sample illustrates yet more syntax elements, you can see the while and if constructs, also how {}
is actually optional when it is a single statement. Also some comments. There is no elseif
construct in Zinc, because as you can see, nesting an if inside an else is just as easy.
Factorial
This simple code is a function that calculates the factorial of a number n, that is 1*2*3*...n
. Notice the for loop construct. It basically means that the code should be repeated for all numbers i between 1 and n. Also notice that two integer variables are declared in the same line. We probably wish to call this function in other libraries, so we declare the function as public.
Instant Kill
This is a quick custom spell that will kill the target unit instantly. You may notice the syntax for return values and also that constant global declaration not inside a globals block.
AddSpecialEffectTimed
This is a library that comes with the AddSpecialEffectTimed, just an example. TimerUtils is a vJass library, but that is not a problem for Zinc. Do notice that all members of a library are private by default, which means that the data struct and the destroyEffect function are private. Public library members also work differently in Zinc than in vJass, it will not add a prefix to the name, therefore the way to call this function is AddSpecialEffectTimed
, not TimedEffect_AddSpecialEffectTimed.
As you can see, things like type casts work the same as in vJass. There is also a struct which follows the same declaration rules as local variables and global variables.
CountUnitsInGroup
This example replicates a blizzard.j function, as an excersise I invite you to check blizzard's implementation of it in Jass. This example features an anonymous function
which are simply a way to allow you to declare functions on the go in cases like this one (very frequent in Jass) where the count=count+1
action is not really part of another function's logic but something inherent to the CountUnitsOne
.