SC2Mapster.com Wiki

Galaxy / Script / Language Overview

Hint

OUTSIDE a function, a variable can only be defined with simple values:

  • int a = 5;
  • U can't use any complex operation.
  • int a = 5+5; will fail, game will not start.

In a function, never define new variable, after some operation.

void test(){
int a = 15;
a+=15;
int b;
}
  • in that case int b will fail.

Language Features

if

if (RandomInt(1, 3) == 1) // Brace required
{
  Print("Good");
}
else if (Random(1, 5) < 4) // else if
{
  Print("Average");
}
else
{
  Print("Bad");
}

while

int i = 0; // You can declare and assign a variable at the same time
while (i < 5)
{
  Print(i);
  i += 1; // Short hand for i = i + 1
}
// Prints 0 1 2 3 4

It is possible to use break and continue from a while loop. There is no for loop. You will have to rewrite all of them using while loops.

variables

  • Allways declare the variables at the beginning of function or script.
  • Never declare them after function calls or logical operations.
int a; // variable declaration
int b = 1; // variable declaration & definition
const int c = 2; // variable that cannot be changed
// Variable must be declared at the top of the function

array

const int array_count = 5; // It must be const
int i = 0;
int[array_count] t; // The [] are next to the type. This is different from C
while (i < array_count)
{
  t[i] = i;
  i = i + 1;
}

See arrays for more details.

struct

struct point2d
{
  int x;
  int y;
}; // Do not forget the ;

point2d A; // Create a variable A of type point2d
A.x = 2;
A.y = 3;
print(A.x);
point2d* B = &A; // Take a pointer of A
Print(B->x);

See structs for more details.

function

int plus(int i, int j)
{
  int result = i + j; // Local variable initialized with arguments
  return result; // Return a result
}

static void private()
{
  // This function can only be called inside the file (because of "static")
}

// Function prototype
native int AIGetRawGasNumSpots (int player, int town);

include

include "Folder/File"; // Include the file "Folder/File.galaxy"

Language Lacks

  • No dynamic allocation: There is no new or malloc. We wonder what would be the use of pointers without this.
  • No pointer Since patch 9, pointer were all removed. With the above lack of new or malloc, pointer were quite limited to begin with.
  • Bulk Copy not supported That with the lack of pointer, array and struct can't be passed to and from functions. It's also impossible to copy them from one variable to another. This with the 2 above render struct and array almost completly useless.
  • No For: Only the while loop is available, the for loop isn't.
  • Weak compiler debugging output: The only error it is able to say is "Syntax Error" and the line where the error happened is not available.
  • No /* ... */ Comments: Maybe it's too hard to code ...
  • Single pass declaration scanning. You have to write the prototype of functions if it is declared after in the file.
  • /=, *= not working properly for fixed
  • Language being based on C. C is an old static language. We expected a dynamic language like Lua. However, this isn't even on par with C... :(
  • Line cannot be > 2048 caracters. Wth ...
  • No trigonometric functions there are sine, cosine, tangent, arcsine, arccosine arctangent form delta and arctangent from value in the Build-In Lib
  • No vectorial functions The functions support around "point" is extremly limited. You got Distance and Angle.
  • No direct accessor to propriety of native classes You have to use native function like PointGetX(), PointGetY()
  • No Quaternion and No Matrix support Seriously, ever tryed doing spatial rotation by hand?

You must login to post a comment. Don't have an account? Register to get one!

  • 3 comments
  • 3 comments