May 23, 2012, 12:44:10 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 to specific objects  (Read 674 times)
Spaz
Full Member
***
Posts: 109


View Profile
« on: March 19, 2009, 01:39:51 PM »

Hey guys,

I know this'll be easy for most of you, but I haven't had to think about it until now.  When my player is in one vehicle I need to be able to press a key and have certain things happen in other vehicles that have been spawned by the traffic system.  Something like flash their brights.  Anybody know how to do that?
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #1 on: March 19, 2009, 10:27:22 PM »

Take a peak through the player controller script and see where it's handling the input messages. As soon as that object gets that message, by way of SetControllerVariable, it can perform an action. The player just takes the inputs from the keyboard. The other cars can take the inputs from any source and the variable can be any name.

This is a snippet from the player script to call to action when the "MoveAlongPathTo" is passed to it from any other object.

Quote
void SetControllerVariable( Object@ object, const String& in name, const String& in value)
{
   if (name == "MoveAlongPathTo")
   {
   pathFinder.Clear();
   Object@ goal = object.GetWorld().GetObject( value);
   if (goal != null)
   pathFinder.StartFindPath( object.GetWorld(), object.GetPosition(), goal.GetPosition(), -object.GetCurMatrix().ZAxis);
   aimAtTarget = false;
   return;
   }
}

You see it does a bunch of crap, actually. What's important is this part:

Quote
void SetControllerVariable( Object@ object, const String& in name, const String& in value)
{
   if (name == "MyVariable")
   {
  DoMyStuff();
   return;
   }
}

The other object that sends the variable first needs a handle to the reading object and then it just sets the variable. In the case below, as seen in my demo, this line causes a successful hit on an AI entity with this weapon to tell the AI to move to where it was hit from. It's as generic a mob pulling system as you can find.

Quote
hitObject.SetControllerVariable( "MoveAlongPathTo", muzzlePos);

If you want to control a whole series of other entities based on one object's variable state, then you'll probably want to look into object grouping (of which I haven't quite grasped the power of yet).

Hope that helps some.

« Last Edit: March 19, 2009, 10:30:25 PM by Squat » Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #2 on: March 20, 2009, 11:55:50 AM »

Thanks, Squat.  I'll see if I can get this to work. Smiley
Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #3 on: March 20, 2009, 07:01:39 PM »

Well, I got it to work . . . sort of.  I figured that by getting it to work with one vehicle called "Landcruiser" it would work with any other instance of that vehicle.  So every Landcruiser spawned by the traffic system should flash their brights when I hit the right key on the keyboard.  The weird thing is it only happens to one of them.  The additional spawnings of the Landcruiser vehicle must be referenced as Landcruiser01, Landcruiser02, or something, and I give a very specific call to only "Landcruiser"  Oh well, it'll suit my purposes for now, but I wish I understood it better. Undecided 
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #4 on: March 23, 2009, 12:25:38 PM »

I think that's where you can take advantage of object groups. You should be able to assign actions to the entire group. Again, I'm unfamiliar how this works.

The other idea is to actually count the # of landcruisers that are spawned in the world and use that variable to set up a for loop that will send the action to each and every one of them in sequence. The good news is that they ARE numbered 01, 02, 03...etc.

If you just pass a regular variable to an object, it's per that instance. If, however, you pass a controller variable, that is per the actual script itself and will maintain count. The way I've been handling these kinds of instances is to use a dummy control object. Usually a box that's named "Landcruiser_Global" and in that I set the count variable (and any others that need to keep a running count). You then use the initialize function for each Landcruiser to boost that variable up by one on the global object by first getting a handle to the global object and then setting the controller variable to +1. Make sure that the script first retrieves the variable before updating it, or each one will merely set it to 0 + 1.

If you peak at my old cheese pickup example, you can find the same kind of theory in action.
Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #5 on: March 23, 2009, 06:32:26 PM »

Thanks, Squat.  I'll take a look at your cheese example. 
Logged
gekido
Guest
« Reply #6 on: April 15, 2009, 11:39:24 AM »

The biggest thing to remember when using the traffic system is that you have a common pool of objects that are essentially hidden & shown as they are moved around the world.  The traffic manager is basically responsible for teleporting them around the world based on where the player / camera currently is located.

The traffic manager communicates with the individual objects through a couple of SetControllerVariable commands:

void SetControllerVariable( Object@ object, const String& in name, int value)
{
    if (name == "TrafficManagerActivate")
    {
          // do special activation stuff here
     }
    if (name == "TrafficManagerDeActivate")
    {
          // do special de-activation stuff here
    }
}

So if you need to communicate / track things on a per-object basis, you can use these functions to reset objects / variables or otherwise figure out when an object has been spawned or deactivated.

Hope this helps.
Logged
zknack
Full Member
***
Posts: 207


View Profile
« Reply #7 on: April 15, 2009, 02:39:26 PM »

That helped me a little Gekido - wish I was more of a programmer.. Is there any chance on any of the
upcoming sample projects that we can get an example of the traffic system working in one of them-
mayhaps in the adventure game example?

Maybe something like an objective of 'talk to the girl in the pink top' - who would be in a crowd of lego
people controlled by the traffic system..?

Would be helpful for those of us who are more artists, and less programmers :-)
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!