Click or drag to resize

ASLObjectSendFloatArray Method

Send and set up to a maximum of 1000 float value(s). The float value(s) will then be processed by a user defined function. If you need to send more than 1000 floats with this object, or you need this object to perform more than one action with this function, then a switch statement is a good way to implement what you need.

Namespace:  ASL
Assembly:  Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0.0.0
Syntax
public void SendFloatArray(
	float[] _f,
	GameLiftManagerOpFunctionCallback _callback = null
)

Parameters

_f
Type: SystemSingle
The float value to be passed to all users
_callback (Optional)
Type: ASLGameLiftManagerOpFunctionCallback
The optional callback function for OpFunction
Examples
void SomeFunction()
{
    //Claim the object first
    gameobject.GetComponent<ASL.ASLObject>().SendAndSetClaim(() =>
    {
        float[] myValue = new float[1];
        myValue[0] = 3.5;
        //In this example, playerHealth would be updated to 3.5 for all users
        gameobject.GetComponent<ASL.ASLObject>().SendFloatArray(myValue); 
    });
}
The same gameobject would then also have these qualities: 

void Start()
{
    //Or if this object was created dynamically, then to have this function assigned on creation instead of in start like this one is
    gameobject.GetComponent<ASL.ASLObject>()._LocallySetFloatCallback(UserDefinedFunction) 
}
//Assuming it is properly linked via the float callback function (see void Start() in this example)
//This function executes upon receiving the SendFloatArray() packet from the server, even if you are the player that called that function
public void UserDefinedFunction(string _id, float[] _f) 
{
    //Update some value for all users based on _f. 
    //Example:
    playerHealth = _f[0]; //Where playerHealth is shown to kept track/shown to all users
}
It is possible to use this function to send more than 1000 variables if the user sets up the function to execute upon receiving SendFloatArray to include a switch statement with the final value (really, any value you want) in the float array being what determines how the other values are handled. See below for an example
//For example, use this function to update player stats using the same SendFloatArray UserDefinedFunction that can also update velocity and score
void SomeFunction()
{
    gameobject.GetComponent<ASL.ASLObject>().SendAndSetClaim(() =>
    {
        float[] myValue = new float[1];
        myValue[0] = 3.5f;
        myValue[1] = 0;
        myValue[2] = 1.2f;
        myValue[3] = 2;
        //In this example, playerHealth would be updated to 3.5 for all users, playerArmor to 0, playerSpeedBuff to 1.2, and the switch case to properly assign these values, 2
        gameobject.GetComponent<ASL.ASLObject>().SendFloatArray(myValue); 
    });
}
//For example, use this function to update velocity using the same SendFloatArray UserDefinedFunction that can also update player stats and score
void SomeOtherFunction()
{
    //Claim the object
    gameobject.GetComponent<ASL.ASLObject>().SendAndSetClaim(() =>
    {
        float[] myValue = new float[4];
        myValue[0] = 17.8f;
        myValue[1] = 180.2f;
        myValue[2] = 1.2f;
        myValue[3] = 1;
        //In this example, velocity would be set to 17.8 and direction to 180.2
        gameobject.GetComponent<ASL.ASLObject>().SendFloatArray(myValue); //Send the floats
    });
}

void Start()
{
    //Or if this object was created dynamically, then to have this function assigned on creation instead of in start like this one is
    gameobject.GetComponent<ASL.ASLObject>()._LocallySetFloatCallback(UserDefinedFunction) 
}
//Assuming it is properly linked via the float callback function (see void Start() in this example)
//This function executes upon receiving the SendFloatArray() packet from the server, even if you are the player that called that function
public void UserDefinedFunction(string _id, float[] _f)
{
    //Update some value for all users based on _f and update 1 object specifically. 
    //Example:
    //If we find the object that called this operation
   if (ASL.ASLHelper.m_ASLObjects.TryGetValue(_id, out ASL.ASLObject myObject))
   {
        switch (_f[3])
        {
            case 0:
                //Update score based on _f[0] for example
                break;
            case 1:
                //Update player velocity and direction with f[0] and f[1] for example
                playerVelocity = _f[0]; //Velocity gets set to 17.8
                playerDirection = _f[1]; //Player Direction gets set to 180.2
                break;
            case 2:
                playerHealth = _f[0]; //Health gets assigned to 3.5
                playerArmor = _f[1]; //Armor gets assigned to 0
                playerSpeedBuff = _f[2]; SpeedBuff gets assigned to 1.2
                break;
            case 3:
                myObject.GetComponent<RigidBody>().velocity = _f[0];
                myObject.GetComponent<MyScript>().MyVariable = _f[1];
                break;
        }
    }
}
See Also