Float, String in return?
#1

Hi, I would like to know how you can through the 'return' variable 'float' and 'string'..

example:

GameMode:

Code:
new Name[150];
new Coords[3] = 0.0;

forward ExampleFunc(playerid);
public ExampleFunc(playerid)
	return Name[playerid];

forward ExampleFunc2(a);
public ExampleFunc2(a)
	return Coords[a];
Filterscript:

Code:
SendClientMessage(playerid, 0x000000AA, "The veh name: %s", CallRemoteFunction("ExampleFunc", "d", playerid));
SetPlayerPos(CallRemoteFunction("ExampleFunc2", "i", 0), CallRemoteFunction("ExampleFunc2", "i", 1), CallRemoteFunction("ExampleFunc2", "i", 2));
Unfortunately does not work..

How do you do?
Maybe you know some other way of communication between GM and FS


Please help.
Reply
#2

pawn Code:
SetPlayerPos(CallRemoteFunction("ExampleFunc2", "f", 0), CallRemoteFunction("ExampleFunc2", "f", 1), CallRemoteFunction("ExampleFunc2", "f", 2)
https://sampwiki.blast.hk/wiki/CallRemoteFunction check the format strings
Reply
#3

Public functions can't return Strings, Floats..

Try a stock instead:

pawn Code:
printf("%f", TestOne() );

printf("%s", TestTwo() );

stock TestOne()
{
     new Float:Example = 5487.1564;
     return _:Example;
}

stock TestTwo()
{
    new string[] = "TESTING THE STRING!";
    return string;
}
Reply
#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
#5

Quote:
Originally Posted by PowerPC603
View Post
CallRemoteFunction only returns integers. I've tested this too and struggled with it, until I found a work-around:
Quote:
Originally Posted by iPLEOMAX
View Post
Public functions can't return Strings, Floats..
Wrong ─ either public functions and CallRemote/LocalFunction CAN return floats. For strings, you can use a global string-variable or, properties to share data through all scripts.
pawn Code:
foo(Float: fVal); public foo(Float: fVal)
{
    return _: fVal;
}
printf("%f", CallRemoteFunction("foo", "f", 12.345678));
Reply
#6

Oh, Alright. Thanks for correcting me RyDeR`
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)