PDA

View Full Version : Speedo not updating


Dripac
28/04/2012, 09:17 PM
stock SetSpeed(playerid)
{
for(new b = 0;b<currentid +1;b++)
{
new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(play erid),SpeedCameras[b][_usemph]));
new string[140];
if(speed < 100)
{
format(string, sizeof(string), "Speed: ~g~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 100)
{
format(string, sizeof(string), "Speed: ~y~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 119)
{
format(string, sizeof(string), "Speed: ~r~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
}
}

Speedo0[i] = TextDrawCreate(496.000000,336.000000,"Speed: ~g~0 KM/h");

The textdraw is showing, but it always says "Speed: 0 KM/h"

The DeLuca
28/04/2012, 09:19 PM
Make sure it updates OnPlayerUpdate or on a repeating timer every second.

Dripac
28/04/2012, 09:20 PM
Make sure it updates OnPlayerUpdate or on a repeating timer every second.

I have it at a timer which updates every 1 second

SetSpeed(i);

The DeLuca
28/04/2012, 09:22 PM
Make SetSpeed a public callback and forward it. See if that works for ya.

Dripac
28/04/2012, 09:24 PM
But what will be the difference =/

I also have a same thing with SetHealth (vehicle health), and it updates

Jonny5
28/04/2012, 10:32 PM
you have not defined currentid

not sure if this is a global or not, only error i spotted.


i dont know this code well but seams more logical to me to have it something like

stock SetSpeed(playerid)
{
for(new b = 0,currentid=sizeof(SpeedCameras);b<currentid;b++)
{
new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(play erid),SpeedCameras[b][_usemph]));
new string[140];
if(speed < 100)
{
format(string, sizeof(string), "Speed: ~g~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 100)
{
format(string, sizeof(string), "Speed: ~y~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 119)
{
format(string, sizeof(string), "Speed: ~r~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
}
}

Dripac
28/04/2012, 10:36 PM
you have not defined currentid

not sure if this is a global or not, only error i spotted.

If i wouldn't have defined it, i would get errors at compiling...

// EDIT, lol your code works, but i get one warning

warning 219: local variable "currentid" shadows a variable at a preceding level

What should i change?

Jonny5
28/04/2012, 10:39 PM
not always true!!!

btw are you using SetTimerEx or SetTimer?
also for it to find your SetSpeed it MUST be public and forward.
this is the ONLY way to use the function with a timer.

edit:


for(new b = 0,cid=sizeof(SpeedCameras);b<cid;b++)


i made it cid..

regards,

Dripac
28/04/2012, 10:42 PM
It works now, thank you.

+rep