May 22, 2012, 04:46:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Passing Variables  (Read 763 times)
Squat
Hero Member
*****
Posts: 592


View Profile
« on: August 26, 2008, 09:59:27 PM »

Sorry for the newbie question, but how do I have the interaction between one object control a variable in another one?

I'll try to explain. I have a ball coded so that if it moves fast enough, an AI character moves to it and when the ball stops, the character is told to stop. I'm using the pathfinder. I also want to have it so that when I go over to another particular object, in this case a mug, the AI character moves over to it. The problem is that when the ball stops, it's stop command to the AI is conflicting with the other object's move commands. While I'm in the input radius of the mug, the character starts and stops in place, basically vibrating. Mug says go, ball says stop. I put both in dynamic advance.

I wanted to have a control variable on the mug that the ball would read. Basically, the ball will only issue the stop command if it's stopped && the variable in the mug's input area says it's ok. How would I do that?
Logged
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #1 on: August 26, 2008, 10:38:58 PM »

Take a look at these built-in functions:

GetControllerVariable
http://www2.gamecore.ca/docs/node/480

GetControllerSetting
http://www2.gamecore.ca/docs/node/479

Does this info suffice?
Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #2 on: August 26, 2008, 11:23:56 PM »

I believe it will, thanks for that.
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #3 on: August 27, 2008, 01:35:58 AM »

can't get it working using that
« Last Edit: August 27, 2008, 02:31:20 AM by Squat » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #4 on: August 27, 2008, 01:58:50 AM »

I am total noob at coding so i can't really help here but:

Code:
void Initialize( Object@ object)
{
object.SetControllerVariable( "Occupied", false);
}

Doesn't the object.SetControllerVariable need to be defined in the beginning in script? And then added to the objects .opr

In the FPS demo i have this from RPG.gsl:

Code:
Player@ player = game.CreatePlayer( "Player", true);
Object@ playerObject = game.GetWorld().GetObject( "Soldier");
playerObject.SetControllerVariable( "CameraMode", "3rdPerson");

And in character.gsl:

Code:
void SetControllerVariable( Object@ object, const String& in name, const String& in value)
{
if (name == "CameraMode")
{
if (value == "1stPerson")
{
firstPerson = true;
return;
}
if (value == "3rdPerson")
{
firstPerson = false;
return;
}
return;
}
}


Hope this helps a bit but i don't know how to use it Smiley


Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #5 on: August 27, 2008, 03:28:45 AM »

I'm still working on it, I'll let you know what I come up with. I'm getting close, but I ended up with a variable that is always false.
Logged
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #6 on: August 27, 2008, 11:22:30 AM »

If you want to pass a variable from one controller script to another, then you use the syntax for getting or setting a Controller Variable.

But if you want the controller script to read a value of a property in the opr file linked to it, then you use GetControllerSetting.

Create a FPS multiplayer template, for example, and take a look at the character.gsl script, inside of the character object folder.

I?ll paste some parts of its code here:

The character.gsl has in the top:

Code:
// constants (modifiable from controller settings, see Initialize function)
float WALK_SPEED = 2.0;
float RUN_SPEED = 4.0;
Vector CAMERA_TARGET( 0.0, 1.0, 0.0);
Vector CAMERA_OFFSET( 0.0, 1.0, 3.0);
Vector FIRST_PERSON_EYE_POSITION( 0, 1.7, 0);
const float MOUSE_LOOK_MULTIPLY = 90 / PI;


Then, inside of Initialize(), it has:

Code:
void Initialize( Object@ object)
{
        //(code for other stuff)

WALK_SPEED = object.GetControllerSettingFloat( "WalkSpeed", WALK_SPEED);
RUN_SPEED = object.GetControllerSettingFloat( "RunSpeed", RUN_SPEED);

//(code for other stuff)
}

And, of course, they have this in the opr file linked to the controller (I?m stripping out the code for other stuff):

Code:
ControllerType Scripted
ControllerSetting ScriptFile character.gsl
ControllerSetting WalkSpeed 4.0
ControllerSetting RunSpeed 6.0

Hope you?ve understood. Did you?
« Last Edit: August 27, 2008, 11:29:17 AM by grubert » Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #7 on: August 27, 2008, 11:55:29 AM »

This code was for getting controller settings.
Now to get one variable from one object to another, as you said, you put this in your controller script, preferrably (for organization) in the part where you?ve put your own functions.
Now I?ll borrow some of a script I?ve wrote (for the airplane withe the mounted gun). At its bottom I have:
Code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GETs AND SETs FOR CONTROLLER VARIABLES
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool GetControllerVariableBool(Object@ object, const String& in name){
if (name == "gun_fire_pressed")
return gun_fire_pressed_out;

if(name == "isHittingEnemyCessna"){
if(attacked_obj_name == "enemy_cessna")
return true;
if(attacked_obj_name != "enemy_cessna")
return false;
}
if(name == "isHittingVictim"){
if(attacked_obj_name == "victim")
return true;
if(attacked_obj_name != "victim")
return false;
}
return false;
}

String GetControllerVariableString(Object@ object, const String& in name){
if(name == "hitObjectName"){
return attacked_obj_name;
}
return " ";
}

Then you?ll need to type, in the controller passing the function, a SetControllerVariableString() function. In this case, as the value being get is a string, you?ll need SetControllerVariableString(), if it was a float you would need a SetControllerVariableFloat() -

Do a search for the complete syntax of the SetControllerVariableXXX() functions. I?m not finding it in the User Guide.


Cheers.
Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
gekido
Guest
« Reply #8 on: August 29, 2008, 06:07:55 PM »

There's a whole other discussion thread that I've been (hopefully) explaining how passing info from one object to another works:

http://www2.gamecore.ca/forums/index.php?topic=112.0

I have also combined all of the controller functions into one section of the docs with the same basic info here:

http://www2.gamecore.ca/docs/scripting-reference/classes/Object/controller-functions
Logged
Pages: [1]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!