Weird crash, if I add something
#1

Working:
pawn Код:
public DashUpdate(playerid)
{
      new vehid = GetPlayerVehicleID(playerid);
      new estring[7];
      switch(EngineStatus[vehid])
      {
         case 0: estring = "Off";
         case 1: estring = "On";
         default: estring = "Broken";
      }
      new tstring[300];
      format(tstring,sizeof(tstring),"Engine: %s~n~Fuel: %d~n~Speed: %d KM" , estring, Fuel[vehid], GetVehicleSpeed(vehid));
      TextDrawSetString(Dash[playerid], tstring);
      TextDrawHideForPlayer(playerid,Dash[playerid]);
      TextDrawShowForPlayer(playerid,Dash[playerid]);
     return 1;
}
Not Working:
pawn Код:
public DashUpdate(playerid)
{
    new State = GetPlayerState(playerid);
    if(State == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid))
    {
      new vehid = GetPlayerVehicleID(playerid);
      new estring[7];
      switch(EngineStatus[vehid])
      {
         case 0: estring = "Off";
         case 1: estring = "On";
         default: estring = "Broken";
      }
      new tstring[300];
      format(tstring,sizeof(tstring),"Engine: %s~n~Fuel: %d~n~Speed: %d KM" , estring, Fuel[vehid], GetVehicleSpeed(vehid));
      TextDrawSetString(Dash[playerid], tstring);
      TextDrawHideForPlayer(playerid,Dash[playerid]);
      TextDrawShowForPlayer(playerid,Dash[playerid]);
    }
    else
    {
       TextDrawHideForPlayer(playerid,Dash[playerid]);
       KillTimer(DashUpdate(playerid));
    }
    return 1;
}
Why is the not-working one causing the server to crash, and how can I fix it. This is really confusing
Reply
#2

Try debugging..

pawn Код:
public DashUpdate(playerid)
{
    print("a");

    new State = GetPlayerState(playerid);

    if(State == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid))
    {
        print("b");

        new vehid = GetPlayerVehicleID(playerid);
        new estring[7];

        switch(EngineStatus[vehid])
        {
            case 0: estring = "Off";
            case 1: estring = "On";
            default: estring = "Broken";
         }

         print("c");

         new tstring[300];

         format(tstring,sizeof(tstring),"Engine: %s~n~Fuel: %d~n~Speed: %d KM" , estring, Fuel[vehid], GetVehicleSpeed(vehid));

         print("d");

         TextDrawSetString(Dash[playerid], tstring);

         print("e");

         TextDrawHideForPlayer(playerid,Dash[playerid]);
         TextDrawShowForPlayer(playerid,Dash[playerid]);
         
    }
    else
    {
        print("f");

        TextDrawHideForPlayer(playerid,Dash[playerid]);
        KillTimer(DashUpdate(playerid));

        print("g");
    }
    return 1;
}
For example, say the last thing it would print in your server log is "d" then we can assume it's crashing at TextDrawSetString(Dash[playerid], tstring);
Reply
#3

I know the problem.

You cannot kill timers if you've only implemented them, you need to assign a variable to the timer first before killing it.

For example:
pawn Код:
new timer_dash_update;

timer_dash_update = SetTimerEx("DashUpdate",time,true/false,"i",playerid);

KillTimer(timer_dash_update);
Sneaky, hats off for the effort but you've missed the main problem ^
Reply
#4

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
I know the problem.

You cannot kill timers if you've only implemented them, you need to assign a variable to the timer first before killing it.

For example:
pawn Код:
new timer_dash_update;

timer_dash_update = SetTimerEx("DashUpdate",time,true/false,"i",playerid);

KillTimer(timer_dash_update);
Sneaky, hats off for the effort but you've missed the main problem ^
I don't know whether the timer is the problem or not but I'm actually trying to learn this guy something (debugging code), if he would debug he would figure out himself whats wrong, you just gave him the (possible) answer and he learns nothing!
Reply
#5

Quote:
Originally Posted by -Sneaky-
Посмотреть сообщение
I don't know whether the timer is the problem or not but I'm actually trying to learn this guy something (debugging code), if he would debug he would figure out himself whats wrong, you just gave him the (possible) answer and he learns nothing!
Well, very kind of you, but I'm also sure that's the real problem as I've encountered it couple of times, so I suggested a quick fix for a common problem, but you're pretty right as debugging almost always helps to find out mistakes.
Reply
#6

Thank-you for the Timer help.

I always debug, and yes I did learn something.

That you cannot kill a timer with variables.
Reply
#7

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
Well, very kind of you, but I'm also sure that's the real problem as I've encountered it couple of times, so I suggested a quick fix for a common problem, but you're pretty right as debugging almost always helps to find out mistakes.
Yep, if only people would do it more often
Reply
#8

Quote:
Originally Posted by GazaWeSay
Посмотреть сообщение
pawn Код:
public DashUpdate(playerid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
      new vehid = GetPlayerVehicleID(playerid);
      new estring[7];
      switch(EngineStatus[vehid])
      {
         case 0: estring = "Off";
         case 1: estring = "On";
         default: estring = "Broken";
      }
      new tstring[300];
      format(tstring,sizeof(tstring),"Engine: %s~n~Fuel: %d~n~Speed: %d KM" , estring, Fuel[vehid], GetVehicleSpeed(vehid));
      TextDrawSetString(Dash[playerid], tstring);
      TextDrawHideForPlayer(playerid,Dash[playerid]);
      TextDrawShowForPlayer(playerid,Dash[playerid]);
    }
    else
    {
       TextDrawHideForPlayer(playerid,Dash[playerid]);
       KillTimer(DashUpdate[playerid]);
    }
    return 1;
}
If you can read the thread, it says the problem has been fixed.

And the code you posted would not work anyways.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)