void SetControllerVariable( Object@ object, const String& in name, const String& in value)
void SetControllerVariable( Object@ object, const String& in name, float value)
void SetControllerVariable( Object@ object, const String& in name, int value)
void SetControllerVariable( Object@ object, const String& in name, bool value)
void SetControllerVariable( Object@ object, const String& in name, const Vector& in value)
Set functions don't return a value (hence are 'void') because you aren't getting anything back from the controller, you are 'setting' a value to whatever you want. The important part that you're missing is in bold - ie the type of parameter that you are looking to set - whether it's a String, float, int or otherwise.
The SetControllerVariable and GetControllerVariable functions are used whenever you want to communicate information between one object and another. This is part of the GameCore's 'Object-Oriented' nature.
For example, you have an object in your world that you want to query for some information, like 'IsAlive'. You can't simply access a variable directly in the controller (because it's a part of the object), so instead you query it using the 'GetControllerVariable()' function that corresponds to the variable type you are requesting.
So, using the 'IsAlive' example I've mentioned.
1) object A wants to know if object B 'is alive' or not.
in object A, you would get a handle to object B, like so:
Object@ objectB = GetGameManager().GetWorld().GetObject("ObjectB");
This gets you a handle (pointer) that you can then use to call functions on object B.
You can then ask object B if it's alive, like so:
bool isBalive = objectB.GetControllerVariableBool("IsAlive");
Note that the Get functions need to know what kind of information is being returned, so there are specific calls for each variable type (bool, int, etc).
Now that we know whether it's alive or not, we can then tell it what we want it to do:
if (isBalive)
{
objectB.SetControllerVariable( "IsAlive", false);
}
basically this says 'if object B is alive, then tell it to be NOT alive'.
Using this same basic technique you can communicate any information that you want between objects as desired. Any time you need to pass information to or from an object that is specific to the script / gameplay (and not something that is provided by a standard GameCore function, like GetPosition() ), you would use the Set/Get ControllerVariable functions to do so.
Now, to complete the above example, ObjectB needs to handle the information that is being passed to it and then do whatever is necessary as a result. Note that this isn't done automatically (we can't guess what you might want to do with the information), so it's up to you to handle the query from the recieving object end.
When it comes down to it, the SetControllerVariable() and GetControllerVariable() functions aren't really 'functions', but function 'templates' that you then flesh out however you need / want.
So, for objectB, we need to add the function definition to recieve the information being sent:
// in the 'globals' area of the script, we have a variable defined that the script uses:
// note that this 'isAlive' variable exists only in Object B and needs to be handled elsewhere in the script.
bool isAlive = true;
void SetControllerVariable( Object@ object, const String& in name, bool value)
{
if (name == "IsAlive")
{
// someone is trying to set whether we're alive or not, let's handle it
isAlive = value;
}
}
and we need to handle the 'Get' query as well:
bool GetControllerVariableBool( const String& name)
{
if (name == "IsAlive")
return isAlive;
}
=================
It says, object = the object that we use but i don't see it defined
It's the first function parameter - and is passed into the script automatically when the function is called. This is probably the confusing part - even though you only say 'SetControllerVariable("MyVariableName", myVariable)', the recieving script automatically gets the first parameter passed in from the engine.
where is the value?
value is another variable, the last parameter, and is the information that you are passing to the second object.
GetFXManager().CreateFXAtPosition( fx, object.GetCurMatrix().Project( object.GetBoundingBoxCenter()));
I could just make a small bounding box at the tip of rifle and the fx will always be there. Or?
I think this code will get the bounding box of the object controlled by the script. Probably your character, in this case.
Grubert is correct - calling 'object.GetBoundingBoxCenter()' gets the center of the object on a whole - ie for everything included in the OPR file.
BoundingBox is not the same thing as physics box. BoundingBox is an automatically calculated box that wraps the entire object (ie everything in the OPR file). You can see an object's bounding box under the 'options' menu (view bounding box). When you select an object the selection box is also the size of the object's bounding box.
What you COULD do for placing a muzzle flash is place a bone or 'hidden' object in the model and use the GetMesh() functions to get the position of that object when placing your muzzleflash effects. This is one way to do this. Having a bone is probably the best option, because your rifle may be moving around due to animations etc - having a bone positioned at the end of the rifle is what I was planning on doing for the FPS template enhancements that I'm working on.
Hope this clarifies things a bit.