Page 1 of 1

Script Questions: Global Var/Functions and the C language.

PostPosted: Fri Aug 25, 2006 4:39 am
by banner88
I am a bit confused when it comes to using script in the GE - for example, let's say, I wanna declare a couple of global variables to store the player's name, age and gender -

Code: Select all
String g_PlayerName = null;
int g_PlayerAge;
char g_PlayerGender;



The question I have: where do I define them to make them global? I can hardly create them before a main loop as there is no centralized cpp file, right?

Also, where do I declare & define global functions, so that all actors have access to it? Are there things like headers in GE?


Sorry if this is stupid question, I just never worked with game editors before. It was always simple source code. :oops: I mean, I think I understand writing script bound to specific events, not sure about general global definitions.


Also - I never worked with C, only with C++. Apart from the OOP elements, are there major differences? I assume the loops, arrays, ifs, pointers and things like that remain the same.

Thank you. :D

PostPosted: Fri Aug 25, 2006 4:57 am
by makslane
Use the Global Code editor to add global vars, structs, new functions...

Some basic variables types (Integer, float or string) can be added in Script Editor by using the 'Variables' button. In this panel you can add new variables and make global, or actor variable (to make lives...)

You can create variables like in C++, but C only allow add variables in the beginning of a block.

More:
http://game-editor.com/docs/scripting.htm

PostPosted: Fri Aug 25, 2006 4:59 am
by makslane
The Checkers demo is a good place to see how new structs, variables and codes can be used:

http://game-editor.com/games/checkers.zip

PostPosted: Fri Aug 25, 2006 5:05 am
by banner88
Thanks man.

PostPosted: Fri Aug 25, 2006 7:21 am
by banner88
Is there anything close to a "class"? If I wanna set up a class of a monster, which holds:


Code: Select all
public class Monsta
{
int Age
String Race

(Or can you create a struct Race? Is race an actor in GE?)
Code: Select all
int m_Strength
int Health

public int Attack (player MainPlayer, int m_Strength)
{
....;
}
}



Where would I put it, and how would I use it? Can you explain how I'd implement this "monster class" in GE?

Thanks. This is a bit confusing compared to coding into a blank text doc.

PostPosted: Fri Aug 25, 2006 2:01 pm
by makslane
Think in the actor like your class.
If you have an actor Monsta, go to the Script Editor -> Variables and add the new actor variables: Age (type integer), Race (type string)

Image

To make the Attack, just use some event, like a collision.