### Variable Initialization Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Shows examples of initializing integer and float variables, including multiple declarations. ```ZGameEditor Script int status = 1; float positionX = 3, positionY, positionZ; ``` -------------------------------- ### OpenGL Primitive Rendering Start Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Declaration for beginning primitive rendering. ```c void glBegin(int mode) { } ``` -------------------------------- ### Switch Statement Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Executes different code blocks based on the value of an expression. Use for multi-way branching. Example handles cases 0, 1, 2, 3, and a default. ```zgameeditor switch(status) { case 0 : case 1 : case 2 : // when i is 0, 1 or 2 doSomething(); break; case 3 : // when i is 3 doSomethingElse(); break; default : //The default case when i is none of the above } ``` -------------------------------- ### Get Attribute Location Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Shader.md Demonstrates how to obtain the OpenGL handle for an attribute variable named 'position' within a shader. ```cpp positionAttrVar = glGetAttribLocation(MyShader.Handle, "position"); ``` -------------------------------- ### Camera Scrolling Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ZApplication.md Animate the CameraPosition property to create scrolling effects in games. This example demonstrates moving the screen slowly to the left. ```ZExpression App.CameraPosition.X=App.Time * 0.5; ``` -------------------------------- ### While Loop Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Repeats a statement or block as long as a condition is true. Use for loops where the number of iterations is not known beforehand. Example calculates the sum of numbers from 0 to 99. ```zgameeditor int i = 0, j = 0; while(i<100) { j += i; i++; } trace(intToStr(j)); ``` -------------------------------- ### Function Call Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Demonstrates how to call defined functions with appropriate arguments. Ensure argument types match parameter types. ```ScriptingLanguage float var1 = max(2, 4); // 4 float var2 = max3(8,14,-5); // 14 ``` -------------------------------- ### Example WhileExp Expression Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Repeat.md An example expression for the WhileExp property, demonstrating how to control the loop based on the current iteration count. This expression is evaluated after each loop iteration. ```ScriptingLanguage return this.Iteration < 5; ``` -------------------------------- ### If-Then Statement Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Executes a single statement conditionally. Use when a simple condition requires a single action. Example increments PlayerLives if PlayerScore is a multiple of 5000. ```zgameeditor if(PlayerScore > 0 && PlayerScore % 5000 == 0) PlayerLives += 1; ``` -------------------------------- ### glUseShaderProgramEXT Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Installs a program object containing a shader into the current rendering state. ```APIDOC ## glUseShaderProgramEXT ### Description Installs a program object containing a shader into the current rendering state. ### Method void ### Parameters #### Path Parameters - **type** (int) - Description not available - **program** (int) - Description not available ``` -------------------------------- ### Constructor Initialization Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Classes.md Shows how to define and use constructors for initializing class objects. Includes examples of default and parameterized constructors, and calling other constructors. ```zgameeditor class Bullet { private int power; model theModel; Bullet() { theModel = BulletModel; power = 10; } Bullet(int power) { Bullet(); // calling another constructor this.power = power; } } ``` -------------------------------- ### Variable Declaration and Assignment Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Demonstrates the declaration, assignment, update, and usage of an integer variable. ```ZGameEditor Script int a; // declaration a = 23; // assignment a++; // updating value trace(intToStr(a)); // usage - print "24" to Log window ``` -------------------------------- ### Raycast Vehicle Setup Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/zgebullet.txt Functions for configuring and creating raycast vehicles, including tuning parameters and adding wheels. ```C++ void zbtSetVehicleTunning(float suspStiffness, float suspCompression, float suspDamping, float maxSuspTravelCm, float maxSuspForce, frictionSlip) {} ``` ```C++ xptr zbtCreateRaycastVehicle(xptr carChassis, int rightAxis, int upAxis, int forwardAxis) {} ``` ```C++ int zbtAddWheel(xptr vehicle, float connectionPointX, float connectionPointY, float connectionPointZ, float directionX, float directionY, float directionZ, float wheelAxleX, float wheelAxleY, float wheelAxleZ, float wheelRadius, float suspRestLength, int bIsFrontWheel) {} ``` -------------------------------- ### Matrix Multiplication and Transformation Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Types.md Shows how to perform matrix multiplication and modify a model-view matrix for transformations like translation and scaling. ```zgameeditor mat4 m1, m2; // ... mat4 m3 = m1 * m2; ``` ```zgameeditor // inputs float scale = 2.0; vec3 tran = vector3(1, 2, 3); mat4 modelViewMatrix; getMatrix(0, modelViewMatrix); // translate model modelViewMatrix[3,0] += tran.X; modelViewMatrix[3,1] += tran.Y; modelViewMatrix[3,2] += tran.Z; // scale model modelViewMatrix[0,0] *= scale; modelViewMatrix[1,1] *= scale; modelViewMatrix[2,2] *= scale; setMatrix(0, modelViewMatrix); ``` -------------------------------- ### Example Expressions for Condition Component Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Condition.md These examples demonstrate valid expressions that can be used in the 'Expression' property of the Condition component. The component evaluates the expression and executes either the 'OnTrue' or 'OnFalse' list based on the boolean result. ```javascript return 1; ``` ```javascript return CurrentModel.Position.X > 5; ``` -------------------------------- ### If-Then-Else Block Statement Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Executes a block of statements conditionally. Use when multiple actions are needed based on a condition. Example modifies Difficulty and Speed if App.Time > 30 and PlayerLives < 2. ```zgameeditor if( (App.Time > 30) && (PlayerLives < 2) ) { Difficulty *= 1.2; Speed *= 1.2; } ``` -------------------------------- ### Kinematic Character Controller Setup Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/zgebullet.txt Functions for creating and configuring a kinematic character controller, including step height and up axis. ```C++ xptr zbtCreateKinematicCharacterController( xptr ghostObject, float stepHeight) {} ``` ```C++ void zbtDeleteKinematicCharacterController(xptr controller) {} ``` ```C++ void zbtSetCharacterUpAxis(xptr controller, int axis) {} ``` -------------------------------- ### OpenGL Get Functions for Parameters Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Declarations for retrieving various OpenGL state parameters. ```c void glGetBooleanv(int pname,xptr params) { } ``` ```c void glGetDoublev(int pname,xptr params) { } ``` ```c int glGetError() { } ``` ```c void glGetFloatv(int pname,xptr params) { } ``` ```c void glGetIntegerv(int pname,xptr params) { } ``` -------------------------------- ### Method Overriding Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Classes.md Illustrates how a subclass can override a virtual method declared in its superclass to provide a specific implementation. ```zgameeditor class Vehicle { virtual void move() {} } class Car : Vehicle { Engine engine; override void move() { this.engine.start(); } } ``` -------------------------------- ### Method Overloading Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Classes.md Illustrates method overloading within a class, where multiple methods share the same name but have different parameter lists. ```zgameeditor class Math { float sum(float a, float b) { return a + b; } float sum(float a, float b, float c) { return a + b + c; } } ``` -------------------------------- ### Call External Function with Reference Arguments Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ScriptingLanguage.md Example of calling an external library function that uses reference arguments for output parameters. ```zge void zbtGetPositionXYZ (xptr obj, ref float outX, ref float outY, ref float outZ) ``` -------------------------------- ### OpenGL Program Parameter Functions Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Functions for setting and getting program local and environment parameters, as well as program properties and strings. ```C void glProgramLocalParameter4fARB(int target,int index,float x,float y,float z,float w) { } ``` ```C void glProgramLocalParameter4fvARB(int target,int index,xptr params) { } ``` ```C void glGetProgramEnvParameterdvARB(int target,int index,xptr params) { } ``` ```C void glGetProgramEnvParameterfvARB(int target,int index,xptr params) { } ``` ```C void glGetProgramLocalParameterdvARB(int target,int index,xptr params) { } ``` ```C void glGetProgramLocalParameterfvARB(int target,int index,xptr params) { } ``` ```C void glGetProgramivARB(int target,int pname,xptr params) { } ``` ```C void glGetProgramStringARB(int target,int pname,xptr _string) { } ``` ```C void glProgramParameteriARB(int program,int pname,int value) { } ``` -------------------------------- ### Program Parameter Functions Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Functions for setting and getting program local and environment parameters, and querying program properties. ```APIDOC ## glProgramLocalParameter4fARB ### Description Sets a 4-component floating-point local parameter for a program. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **x** (float) - The x component. - **y** (float) - The y component. - **z** (float) - The z component. - **w** (float) - The w component. ## glProgramLocalParameter4fvARB ### Description Sets a 4-component floating-point local parameter for a program using a vector. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **params** (xptr) - A pointer to an array of 4 floats. ## glGetProgramEnvParameterdvARB ### Description Retrieves double-precision floating-point environment parameters for a program. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **params** (xptr) - A pointer to store the retrieved parameters. ## glGetProgramEnvParameterfvARB ### Description Retrieves single-precision floating-point environment parameters for a program. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **params** (xptr) - A pointer to store the retrieved parameters. ## glGetProgramLocalParameterdvARB ### Description Retrieves double-precision floating-point local parameters for a program. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **params** (xptr) - A pointer to store the retrieved parameters. ## glGetProgramLocalParameterfvARB ### Description Retrieves single-precision floating-point local parameters for a program. ### Method void ### Parameters - **target** (int) - The program target. - **index** (int) - The index of the parameter. - **params** (xptr) - A pointer to store the retrieved parameters. ## glGetProgramivARB ### Description Retrieves integer parameters for a program. ### Method void ### Parameters - **target** (int) - The program target. - **pname** (int) - The name of the parameter to query. - **params** (xptr) - A pointer to store the retrieved parameters. ## glGetProgramStringARB ### Description Retrieves a program string. ### Method void ### Parameters - **target** (int) - The program target. - **pname** (int) - The name of the parameter to query. - **_string** (xptr) - A pointer to store the retrieved string. ## glProgramParameteriARB ### Description Sets an integer parameter for a program. ### Method void ### Parameters - **program** (int) - The program object. - **pname** (int) - The name of the parameter to set. - **value** (int) - The value of the parameter. ``` -------------------------------- ### Instantiating and Configuring Models Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Types.md Shows how to create multiple instances of a 'model' component, assign them to variables, and set their properties like position and custom variables. ```ZScript model m; for(int i =0; i < 100; i++) { m = createModel(AsteroidModel); m.Position.X = random(0, 50); m.Position.Y = random(0, 50); m.Position.Z = random(0, 50); m.AsteroidWeight = random(30, 10); // setting of Model's local variable } ``` -------------------------------- ### Get Model View Matrix and Scale X Axis Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/BuiltinFunctions.md Retrieves the current OpenGL model-view matrix, modifies its X-axis scale, and then sets the matrix. Requires prior setup of OpenGL matrices. ```zgameeditor mat4 mvm; getMatrix(0, mvm); mvm[0,0] = 2.5; setMatrix(0, mvm); ``` -------------------------------- ### RemoveModel Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/RemoveModel.md Example of how to remove a model instance using RemoveModel. This is typically done within an expression. ```zgameeditor model myModelInstance = createModel(MyModel); ... @RemoveModel(Model: myModelInstance); ``` -------------------------------- ### Instance Creation Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Classes.md Demonstrates how to create instances of a class using its constructors. ```zgameeditor Bullet b1 = new Bullet(); // power = 10 Bullet b2 = new Bullet(80); // power = 80 ``` -------------------------------- ### Playing Sounds with Compact Syntax Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Types.md Demonstrates playing a sound using both explicit and compact syntax. The compact syntax allows for inline creation and configuration of the Sound object. ```ZScript Sound snd; snd = @Sound(); // create and define a new sound @PlaySound(Sound : snd, NoteNr : 65); // play it ``` ```ZScript @PlaySound( Sound : @Sound(Osc1WaveForm : 1), NoteNr : 60); ``` -------------------------------- ### RenderNet Vertex Expression Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/RenderNet.md An example expression for modifying vertex properties (position, color) for a 20x20 net. This expression is executed for each vertex before rendering. ```csharp float d = sqrt(Vertex.X*Vertex.X + Vertex.Y*Vertex.Y); Vertex.X *= 10; Vertex.Y *= 10; Vertex.Z = cos(d*10); Color.R = abs(Vertex.Z); Color.G = Color.R; Color.B = 1.5 - Color.R; ``` -------------------------------- ### Extract Substring Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/BuiltinFunctions.md Extracts a portion of a string based on a starting position and length. Ensure start position and length are within the source string bounds. ```zgameeditor subStr("hello",0,2); ``` -------------------------------- ### Use Shader Program EXT Source: https://github.com/villekrumlinde/zgameeditor/blob/master/tools/ZDesigner/exe/Lib/opengl.txt Installs a program object as part of current rendering state. Use this to activate a compiled and linked shader program. ```c void glUseShaderProgramEXT(int type,int program) { } ``` -------------------------------- ### Create System Link for OpenGL on Linux Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/ExportLinuxOSX.md On Linux, create a system link for the OpenGL library if the engine cannot find 'libGL.so'. Root privileges are required. ```bash ln -s usr/lib/libGL.so.1 usr/lib/libGL.so ``` -------------------------------- ### Steering Behaviour Expression Example Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/SteeringBehaviour.md Example of how to set the OutVector for a steering behaviour using an expression. This code is intended to be used within the 'Expression' kind of a SteeringBehaviour component. ```javascript this.OutVector.X = 0.5; this.OutVector.Y=0.5; ``` -------------------------------- ### Create component and set properties Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/BuiltinFunctions.md Creates a new component as a child to an existing component and allows setting its properties. This example demonstrates creating multiple bitmap components with varying properties and nested producers. ```zge Component createComponent (Component owner, string propertyListName, string componentClassName) ``` ```zge void setStringProperty (Component component, string propertyName, string value) ``` ```zge void setNumericProperty (Component component, string propertyName, int index, float value) ``` -------------------------------- ### Writing to a File with Compact Syntax Source: https://github.com/villekrumlinde/zgameeditor/blob/master/Docs/Types.md Illustrates writing data to a file using both explicit and compact syntax. The compact syntax simplifies the creation and configuration of the File object. ```ZScript byte[256] buf; for(int i=0; i