3DGS and C-Script

Info on C-Script

nC-Script manual         

nhttp://www.coniserver.de/down/wdlman.pdf

nOn class website

nIn 3DGS folder?

n

n3DGS Tutorial

nhttp://www.conitec.net/tutorial/index.htm

nAvailable from WED help

n

n

n3DGS Forum

nwww.3dgamestudio.com

C-Script

nScripting language (no kidding)

nscripting language: A programming language supported by and specific to a particular program. Note: A scripting program is normally used to automate complex or advanced features or procedures within the program.

nSimilar to C or javascript

nCode in .wdl files (plain text)

nNOT object-oriented

nEvent-driven

nMulti-tasking

nCan be extended using DLL plug-ins

Statements or instructions

n    Like C or javascript

n    Statements end with ;

n    Grouped with { }

n    Comments // or /*  */

Special characters

n;                          statement terminator

n{ }                       enclose function / loop

n“ “                       designate text

n[ ]                        array index

n&                        array parameter

n< >                     enclose file definitions

n//                         comment to end of line

n/*   */                   block comment

Variables

n    FORMAT

n    type name;

n    type name = value;

n    type name { ... }

 

n    Name

n    30 characters

n    Begin with letter

n    Case insensitive

n    No special characters

n   except _

 

EXAMPLES

n    var x;
var y = 1;
var the_flag = off;
var new_array[99];
var loc_vector[3] = 0,0,0;
string the_name = "Steiner";
text mytext { font = standard_font;
                    string = "this is a text!"; }

Variable Types

n   variables

n   Arrays

n   Vectors

n   String

Variables

nFixed point number

n999999.999 to – 999999.999

n

nExamples

nVar x;

nVar y = 99;

n

nX = y + 100;

Arrays

nIndexed variable

nStore numeric data

n

nExamples

nVar x[99];

nVar y[2] = 1,2;

n

nY[0] = x + 1;

Vectors

nArray in multiple of 3

nStores numeric data

nRelated keywords (x,y,z; red,green,blue; roll,pitch,yaw);

n

nExamples

nVar loc[3];

nVar color_vec = 0,0,0;

n

nLoc[0] = 0;

nLoc.x = 0;

Strings

nIndexed variable

nStore text data

n

nExamples

nString t1[30];

nString the_name = “frodo”;

n

nstr_cpy(t1, "hello");  // Good!

nT1 = “hello”;              // generates error

Assignment and expressions

nVar = expression

nvar (+-*/)= expression;

n

nX = 1;

nY = x + 1;

nLoc_vector.roll += 2;

Functions and Actions

n    Functions

n    Scope

n    Function prototype

n    Actions

Functions

nFunction name (parm1, parm2, parm3, parm4) {…}

n

function square(x) {

        x = x * x;

        return(x); }

Scope, variables, arrays

nParameters may be variables or arrays

nVariables are scoped locally

nfunction square(x) {…}

nArrays are handled with pointer and changes are global

nfunction square(&x) {…}

n

nstay tuned for more…

Function prototype

nFunctions must be defined before they are used

nFunctions may be “predefined” using a function prototype

nFunction without the {}

n

nExample

function square(x);

function do_math(y) {return (square(y));}

function square(x) {

            x = x * x;

            return(x); }

Actions

n    Special function assigned to an entity

n    Doesn’t take parameters

n    But entities can have SKILLs

Branching

n     if (expression) { instructions... }

n     if (expression) { instructions... } else { instructions... }

 

n     || true if either is true (or)

n     && true if both are true (and)

n     != true if both are not equal

n     == true if both are equal

n     <= true if the first is below or equal to the second

n     >= true if the first is above or equal to the second

n     < true if the first is below the second

n     > true if the first is above the second

 

If examples

n      if (my.flag1 == off) { // if FLAG1 is not set,

n     y = -1; // then set y and z to -1

n     z = -1;

n      } else {

n     y = 1; // otherwise, set y and z to 1

n     z = 1;

n      }

 

n      if (((x+3)<9) || (y==0)) {

n     // set z to 10 if x+3 is below 9, or if y is equal to 0

n     z = 10;

n      } else {

n     // set z to 5 in all other cases

n     z = 5;

n      }

Loops - While

n    while (expression) { instructions... }

n    break;

n    continue;

while (x < 100) {

X += 1;

}

Loops – Goto

n    Jumps to a target label in the function and proceeds from there with the subsequent instructions. label may be any name followed by a colon as target mark anywhere between two instructions in the function.

 

Again:

    x += 1;

    goto(again);

Components of a C-Script Program

n    MAIN function

n    Include other script files

n    Variable definitions

n    Functions and actions

Sample Program

n    Change background color

n   Screen_color vector

/////////////////////////////////////////////////////////////////

// The main() function is started at game start

function main()

{

   screen_color.blue = 65; // set a dark blue background

  

}

Sample Program

n    Template given by 3DGS

n    Demo99.wdl

Sample Program

n    Create function

n   Double a number

n   Display result

var test_var = 1;

string test_str[30];

path "C:\\Program Files\\GStudio\\template";

include <movement.wdl>;

include <messages.wdl>;

/////////////////////////////////////////////////////////////////

// The main() function is started at game start

function main()

{

   double_num(test_var);  

}

function double_num(num)

{

   num *= 2;

   str_for_num(test_str, num);

   msg_show(test_str,10);

}

Entities

n    Can manipulate attributes of movable objects in environment (entities)

n    Location, orientation, etc.

n    Can use entity functions

n    Can create an ACTION

Sample ACTION

n    Rotate entity (pan)

action spinner

{

   while(1) {

   my.pan += 3;

   wait(1);

    }

}

action spinner2

{

   while(1) {

   my.pan += 3 * time;

   wait(1);

    }

}