static variable works, but not the 'new'
#1

PHP код:
// This belongs under OnPlayerUpdate
static str[7/* Works fine, but when "new str[7]" doesn't work at all and GetVehicleSpeed returns 0. */
new Float:speed GetVehicleSpeed(vid,false);
new 
round floatround(speed);
vid GetPlayerVehicleID(playerid);
format(str,sizeof(str),"%i MPH",round);
PlayerTextDrawSetString(playerid,Speed[playerid],str);
printf("(Speed: %i)",round); 
Already so basically this, when 'str' variable is static it returns the correct speed, but when 'str' isn't static the GetVehicleSpeed returns 0 and I don't think the GetVehicleSpeed function needs to be posted here as it works perfectly when the 'str' variable is static.

"Str" variable isn't static:
pawn Код:
[03:00:18] (Speed: 0)
[03:00:18] (Speed: 0)
[03:00:18] (Speed: 0)
[03:00:18] (Speed: 0)
Variable is a static:
pawn Код:
[03:01:21] (Speed: 47)
[03:01:22] (Speed: 48)
[03:01:22] (Speed: 47)
[03:01:22] (Speed: 46)
[03:01:22] (Speed: 46)
[03:01:22] (Speed: 45)
[03:01:22] (Speed: 44)
[03:01:22] (Speed: 43)
Thanks!
Reply
#2

Seems like OnPlayerUpdate wasn't the right place for this, created a timer which calculates the speed every 500ms fixed it.

Solved.
Reply
#3

It's your own fault for placing it wrong (vid is set after getting the speed).
pawn Код:
new str[7], Float:speed = GetVehicleSpeed(GetPlayerVehicleID(playerid), false);
format(str, sizeof(str), "%i MPH", floatround(speed));
PlayerTextDrawSetString(playerid, Speed[playerid], str);
Static makes the value persist.
Reply
#4

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
It's your own fault for placing it wrong (vid is set after getting the speed).
pawn Код:
new str[7], Float:speed = GetVehicleSpeed(GetPlayerVehicleID(playerid), false);
format(str, sizeof(str), "%i MPH", floatround(speed));
PlayerTextDrawSetString(playerid, Speed[playerid], str);
Static makes the value persist.
Yeah I've noticed that, thanks for the reply though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)