Float, String in return?
#4

CallRemoteFunction only returns integers. I've tested this too and struggled with it, until I found a work-around:

Script: MainScript
pawn Code:
// Global variables on top of your script
new Float:PlayerX, Float:PlayerY, Float:PlayerZ, PlayerName[24];

// This function stores the name and coordinates of the requested player when using the function OtherScript_GetPlayerData
forward MainScript_StorePlayerData(const pName[], Float:pX, Float:pY, Float:pZ);
public MainScript_StorePlayerData(const pName[], Float:pX, Float:pY, Float:pZ)
{
    // Store the name of the player that was passed to this script
    format(PlayerName, sizeof(PlayerName), pName);
    // Store his coordinates
    PlayerX = pX;
    PlayerY = pY;
    PlayerZ = pZ;
}


SomeFunction(playerid)
{
    // Use this function to get data from another script
    CallRemoteFunction("OtherScript_GetPlayerData", "i", playerid);

    printf("PlayerName: %s", PlayerName);
    printf("Coordinates: %f, %f, %f", PlayerX, PlayerY, PlayerZ);
)
Script: OtherScript
pawn Code:
// Put this in the other script
forward OtherScript_GetPlayerData(playerid);
public OtherScript_GetPlayerData(playerid)
{
    // Send the playername and his coordinates back to the mainscript for further use
    CallRemoteFunction("MainScript_StorePlayerData", "sfff", pData[playerid][PlayerName], pData[playerid][PlayerX], pData[playerid][PlayerY], pData[playerid][PlayerZ]);
}
In the main-script, you call the function "SomeFunction" and this will call the remote function "OtherScript_GetPlayerData" and send the playerid as a parameter.

In the other script, the function is executed and sends the name of that player and his coordinates back as parameters using another remote call: "MainScript_StorePlayerData".
This remote function (which is located in the main-script) stores the sent data in global variables.

Then the next lines of the function "SomeFunction" are executed to print the player's name and his coordinates.

So you can pass strings and floats to other script using multiple CallRemoteFunction calls.
Reply


Messages In This Thread
Float, String in return? - by zielu001 - 03.10.2011, 16:34
Re: Float, String in return? - by Pharrel - 03.10.2011, 16:38
Re: Float, String in return? - by iPLEOMAX - 03.10.2011, 17:05
Re: Float, String in return? - by PowerPC603 - 03.10.2011, 17:46
Re: Float, String in return? - by RyDeR` - 03.10.2011, 17:55
Re: Float, String in return? - by iPLEOMAX - 04.10.2011, 20:24

Forum Jump:


Users browsing this thread: 1 Guest(s)