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

Non-platform specific questions.

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

Postby banner88 » Fri Aug 25, 2006 4:39 am

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
banner88
 
Posts: 18
Joined: Thu Aug 24, 2006 10:16 am
Score: 0 Give a positive score

Postby makslane » Fri Aug 25, 2006 4:57 am

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby makslane » Fri Aug 25, 2006 4:59 am

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby banner88 » Fri Aug 25, 2006 5:05 am

Thanks man.
banner88
 
Posts: 18
Joined: Thu Aug 24, 2006 10:16 am
Score: 0 Give a positive score

Postby banner88 » Fri Aug 25, 2006 7:21 am

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.
banner88
 
Posts: 18
Joined: Thu Aug 24, 2006 10:16 am
Score: 0 Give a positive score

Postby makslane » Fri Aug 25, 2006 2:01 pm

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.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest