A programming language is used for creating programs - and the special script language you're about to read here is especially suited for creating multimedia applications or computer games. It's not the only choice. If you only want to 'click together' simple games like shooters, you can do that with the Gamestudio level editor WED, and do not need to read on... but if you're still here, you probably want to program more ambitious projects.
While you can also use an external development system and use languages like C++, C#, or DelphiŪ, you'll get faster results with the lite-C script language. It's a simplified and streamlined version of the professional language C/C++. So as you learn scripting, you're also learning the basics of computer programming. If you want to move on to other modern programming languages, like C#, C++, or Java, the script language is a great introduction. And one of the best things about it is that you can do a great deal with very little programming.
C-Script was the standard script language of Gamestudio up until 2007. It was developed into a new script language, lite-C, in 2007. Lite-C is extremely similar to C-Script - in fact you won't see a difference at a first glance. However at a second glance it offers a lot more possibilities. As to our knowledge, lite-C is the only script language in the world that allows full access to Windows API, DirectX and OpenGl functions. For this purpose it does not only support C syntax but also some C++ features like classes, methods and function overloading. You do not need any other development system - unless you are preferring one because you're used to it.
Enough hype about scripting. If you're new to programming, start with lite-C Tutorial. Even if you already know C or C++, we still recommend the tutorial for learning the special features of C-Script / lite-C compared to the normal C language. For learning standard C programming in detail you can find many fine online tutorials such as Teach Yourself C in 21 Days (English) or C von A bis Z (German).
Lite-C can be used in two modes: Pure Mode and Legacy Mode. Pure mode code is simpler and shorter. It uses the functions of the Acknex engine and does not require programming boring stuff like message loops. In Legacy mode the engine functions are not available, so you need to program everythin manually just as with a standard C++ development system. Legacy mode code however is C++ upwards compatible - it can be compiled not only with lite-C but als with any C++ compiler as long as only standard C features are used.
Feature |
C-Script |
lite-C Pure |
lite-C Legacy |
C |
C++ |
---|---|---|---|---|---|
Standard extension |
.wdl |
.c |
.c |
.c |
.cpp |
Main function |
main() |
main() |
WINAPI WinMain(...) | WINAPI WinMain(...) |
WINAPI WinMain(...) |
Case sensitive | no | yes | yes | yes | yes |
Standard variables |
var |
var, int, long, short, char, float, double |
var, int, long, short, char, float, double |
int, long, short, char, float, double |
int, long, short, char, float, double |
Structs |
predefined only |
yes |
yes |
yes |
yes |
Classes & methods |
no |
external only |
external only |
no |
yes |
Function overloading |
no |
yes |
yes |
no |
yes |
COM / DLL support | plugins only | yes |
yes |
yes |
yes |
Windows API support | no | yes |
yes |
yes |
yes |
Memory protection* |
yes |
yes |
no |
no |
no |
Pointer protection* |
yes |
yes |
no |
no |
no |
Coroutines** | yes | yes | no | no | no |
Multimedia objects *** | yes | yes | no | no | no |
Control functions | if, while | if, while, for, do, switch | if, while, for, do, switch | if, while, for, do, switch | if, while, for, do, switch |
Code compilation | on-the-fly | on-the-fly and in advance | on-the-fly and in advance | in advance only | in advance only |
* Memory protection prevents you from causing 'memory leaks' by automatically freeing allocated engine objects. Pointer protection allows you not to care about the difference between pointers and contents. Both features greatly simplify the language for beginners.
** Coroutines are a method of running many functions simultaneously (multitasking). This is especially needed for 3D computer games. C-Script and lite-C support this through the wait() instruction.
*** Multimedia objects are predefined objects for displaying images, playing sounds, or creating GUI elements and 3D objects.
In the following sections you'll find a description of the variables, objects and functions. Features only available in the upcoming lite-C scripting language are marked with LC . In examples, code differences are marked in different colors: green for lite-C and red crossed-out for C-Script. For converting an old C-script to lite-C, read the migration section.
Below you'll find two examples of a Mandelbrot script written in Pure and Legacy mode. As you see, in Pure Mode the program consists almost only of the functions that draw the Mandelbrot fractal. All stuff unrelated to the program goal, like creating a window and handling a message loop, is automatically dealt with by the compiler.
lite-C Pure Mode | lite-C Legacy Mode |
#include <acknex.h> // Pure Mode |
#include <litec.h> // Legacy Mode ////////////////////////////////////////////////////// // Draw a Mandelbrot fractal. double m_x = 0.344142, m_y = 0.075094, m_width = 0.017813; long JetColor(double v) { double d = 25.0; v = v/d + 0.5; int i = (int)v; int f = (int)(255*(v-i)); int r=0, g=0, b=0; switch(i) { case 0: r=0; g=0; b=f; break; case 1: r=0; g=f; b=255; break; case 2: r=f; g=255; b=255-f; break; case 3: r=255; g=255-f; b=0; break; case 4: r=255-f; g=0; b=0; break; } return r|(g<<8)|(b<<16); } void Draw(HDC hdc,long vw,long vh) { long w = vw; long h = vh; long i,j; long times,inset; double x,y,zx,zy,zxs,zys; long detail=100; for(i=0;i<w;i++) for(j=0;j<h;j++) { x = m_x+((double)i)*m_width/w; y = m_y+((double)(h-j))*m_width/w; zx = 0; zy = 0; inset = 1; times = 0; while(inset && times<detail) { times++; zxs = zx*zx; zys = zy*zy; zy = 2*zx*zy+y; zx = zxs-zys+x; if (zxs+zys >= 4.0) inset=0; } if(inset) SetPixel(hdc,i,j,0); else SetPixel(hdc,i,j,JetColor(times)); } } ///////////////////////////////////////////////////// // message loop function LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch(message) { case WM_LBUTTONDOWN: // zoom in at cursor position { RECT rect; GetClientRect(hWnd,&rect); long x = ((long)lParam)&0xffff; long y = (((long)lParam)&0xffff0000)>>16; double a; a = x; a /= rect.right; m_x += m_width*(a-0.5); a = y; a /= rect.bottom; m_y += m_width*(0.5-a); m_width *= 0.5; InvalidateRect(hWnd,0,0); } break; case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: switch(wParam){ case 1: m_x=-2.5; m_y=-2; m_width=4.0; InvalidateRect(hWnd,0,0); break; case 2: break; case 3: PostMessage(hWnd, WM_CLOSE,0,0); break; } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); RECT rect; GetClientRect(hWnd,&rect); Draw(hdc,rect.right,rect.bottom); EndPaint(hWnd, &ps); break; case WM_KEYDOWN: switch( wParam ) { case VK_ESCAPE: case VK_F12: PostMessage(hWnd, WM_CLOSE,0,0); break; } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } int WINAPI WinMain (WINARGS) { //Create a window char *szClass = "liteCWindowClass"; HINSTANCE hi = GetModuleHandle(NULL); UnregisterClass(szClass,hi); WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW|CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hi; wcex.hIcon = LoadIcon(hi,(LPCSTR)128); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szClass; |
? latest version online