13 years
edited 13 years
Ok, I'm now implementing ZINC syntax in wc3jass.com. Please post code in ZINC here in order to check if it's highlighting it properly.
Thanks.
Thanks.
1 library HelloWorld
2 {3 function onInit()
4 {5 BJDebugMsg("Hello World");6 }
7 }
1 library Bottles99
2 {3 /* 99 Bottles of beer sample,
4 prints the lyrics at: [url]http://99-bottles-of-beer.net/lyrics.html[/url]
5 */
6 function onInit()
7 {8 string bot = "99 bottles";
9 integer i=99;
10 while (i>=0)
11 {12 BJDebugMsg(bot+" of beer on the wall, "+bot+" of beer");
13 i=i-1;
14 if (i== 1) bot = "1 bottle";
15 else if (i== 0) bot = "No more bottles";
16 else bot = I2S(i)+" bottles";
17 //Lazyness = "No more" is always capitalized.
18 19 if(i>=0)
20 {21 BJDebugMsg("Take one down and pass it around, "+bot+" of beer on the wall.\n");22 }
23 }
24 BJDebugMsg("Go to the store and buy some more, 99 bottles of beer on the wall.");25 }
26 }
1 library Test
2 {3 function test1()
4 {5 //Also refer to the CountUnitsInGroup example ...
6 TimerStart(CreateTimer(), 5.0, false, function() {7 BJDebugMsg("5 seconds since you called test1");8 });
9 }
10 11 12 type unitFunc extends function(unit);
13 function AllyEnemyFunctionPicker(player p, unit u, unitFunc F, unitFunc G)
14 {15 if (IsUnitAlly(u, p) ) {16 F.evaluate(u);
17 } else {18 G.evaluate(u);
19 }
20 21 }
22 /* those things up there are just the function pointers example */
23 24 function test2(unit u)
25 {26 unitFunc F, G;
27 28 F = function(unit u) {29 BJDebugMsg("We are torturing "+GetUnitName(u)+" again");30 KillUnit(u);
31 };
32 33 G = function(unit u) { SetWidgetLife(u, 100); };34
35 AllyEnemyFunctionPicker( Player(0), u, F, G);
36 // will torture the unit if it is an ally, or heal it otherwise.
37 // notice this does the same as the function pointers example.
38 }
39 40 }
41
1 library Test
2 {3 //a function type with a single unit argument
4 type unitFunc extends function(unit);
5 6 //a function type with two integer arguments that returns boolean
7 type evFunction extends function(integer,integer) -> boolean;
8 9 function TortureUnit(unit u)
10 {11 BJDebugMsg(GetUnitName(u)+" is being tortured!");
12 KillUnit(u);
13 }
14 15 function HealUnit(unit u)
16 {17 SetWidgetLife(u, 1000);
18 }
19 20 /* This function calls F(u) if the unit is an ally or G(u) if the unit is an enemy
21 the example sucks as it is much slower than an if-else but should be good
22 to explain it... */
23 function AllyEnemyFunctionPicker(player p, unit u, unitFunc F, unitFunc G)
24 {25 if (IsUnitAlly(u, p) ) {26 F.evaluate(u);
27 } else {28 G.evaluate(u);
29 }
30 31 }
32 33 function test(unit u)
34 {35 // We are using the functions as arguments here...
36 AllyEnemyFunctionPicker( Player(0), u, TortureUnit, HealUnit );
37 38 // will torture the unit if it is an ally, or heal it otherwise.
39 }
40 41 }