Accessing floats from a different script -
Stinged - 05.06.2016
I've been scripting for a while now, and I've never needed to access a float that's inside the gamemode, from a filterscript.
I've never had a problem when I access integers.
(I use CallRemoteFunction)
This is just an example of course:
Код:
Gamemode:
public Float: GetPlayerHealthEx(playerid)
{
new Float: f;
GetPlayerHealth(playerid, f);
return f;
}
Filterscript:
CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
Maybe I'm doing something completely stupid and I'm not noticing it, but it's not working.
I tried debugging, and all it did is make me more confused:
Код:
new
Float: test = 100.0,
Float: h = GetPlayerHealthEx(playerid);
printf("test: %f", test);
printf("h: %f", h);
if (test > h)
print("test > h");
What it prints out:
Код:
test: 100.000000
h: 50.000000
The only way I'm getting it to work is by using PVars..
Re: Accessing floats from a different script -
Konstantinos - 05.06.2016
Have from the gamemode the public function with Float: tag to return the float value and in filterscript:
pawn Код:
new
health = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
printf("health from fs: %f", Float: health);
Re: Accessing floats from a different script -
Spmn - 05.06.2016
You could also use PVars ([G/S]etPVarFloat)
Re: Accessing floats from a different script -
Stinged - 05.06.2016
Quote:
Originally Posted by Spmn
You could also use PVars ([G/S]etPVarFloat)
|
I did change it to that before making this thread, but I prefer using normal variables.
Quote:
Originally Posted by Konstantinos
Have from the gamemode the public function with Float: tag to return the float value and in filterscript:
pawn Код:
new health = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
printf("health from fs: %f", Float: health);
|
Thank you Konstantinos, it works!
"You must spread some Reputation around before giving it to Konstantinos again."
Damn it..
Re: Accessing floats from a different script -
IFilip - 05.06.2016
I give you some advice, do not create a variable equivalent to HP, as with GetPlayerHealthEx function return the float value
change in
pawn Код:
printf("h: %f", GetPlayerHealthEx(playerid));
Re: Accessing floats from a different script -
Stinged - 05.06.2016
I was only giving an example, but creating a variable and setting it to something, and then using that variable multiple times it better than using CallRemoteFunction multiple times.
Код:
new Float: h = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
if (h ...)
else if (h ...)
printf("%f", h);
SetPlayerHealth(playerid, h);
is better than
Код:
if (CallRemoteFunction("GetPlayerHealthEx", "i", playerid) ...)
else if (CallRemoteFunction("GetPlayerHealthEx", "i", playerid) ...)
printf("%f", CallRemoteFunction("GetPlayerHealthEx", "i", playerid));
SetPlayerHealth(playerid, CallRemoteFunction("GetPlayerHealthEx", "i", playerid));
Re: Accessing floats from a different script -
Nero_3D - 05.06.2016
The problem is that CallRemoteFunction don't know the correct tag and treats the float as integer
To save memory and the problem with the tag you should either create a function or use native
With native this could look like
PHP код:
// Float: GetPlayerHealthEx(playerid) - returns current health
native Float: _GetPlayerHealthEx(func[] = "GetPlayerHealthEx", form[] = "i", {Float, _}: ...) = CallRemoteFunction;
#define GetPlayerHealthEx( _GetPlayerHealthEx(_,_,
Re: Accessing floats from a different script -
Stinged - 05.06.2016
Thank you Nero_3D.
Would there be any difference in speed and memory usage if I do this:
[/code]#define GetPlayerHealthEx(%0) Float: CallRemoteFunction("GetPlayerHealthEx", "i", %0)[/code]
Instead of what you posted?
Re: Accessing floats from a different script -
Nero_3D - 05.06.2016
Quote:
Originally Posted by Stinged
Thank you Nero_3D.
Would there be any difference in speed and memory usage if I do this:
[/code]#define GetPlayerHealthEx(%0) Float: CallRemoteFunction("GetPlayerHealthEx", "i", %0)[/code]
Instead of what you posted?
|
Speed-wise it would be the same but memory-wise not, if you do it like that both strings would be placed again and again into the memory, with the natives it would be as if you had declared both string global and reuse them each time
Re: Accessing floats from a different script -
Stinged - 05.06.2016
Alright, thanks for the help.