[Tutorial] How to find bugs
#1

Hi everyone, this is another tutorial by me
I'm gonna explain (little tutorial) how to find bugs / non-working scripts.
Did you ever had this? You had no warnings/errors while compiling, but when playing, it isn't working. This ain't nice at all. It's just easy to find: DEBUG IT

Before you're gonna ask, what is 'debug'? It ain't 'debug' of course XD - It's 'debugging'. With debugging, you can find bugs... That's why I made this tutorial. It's actually "How to debug". Follow these 2 steps.

Step 1: Go after what isn't working
The step title says it. If you made a lock pick system, for example, and it isn't working / not working properly, find in the gamemode/filterscript the part that isn't working! If you need to press "LOOK_BEHIND" for that script, search for "KEY_LOOK_BEHIND" or "512". ( KEY_LOOK_BEHIND = key 512 ). There you can find the script you're gonna need probably

Step 2: Add debugging messages
After finding the code, there are 2 options:
1) Add console prints / client messages
2) Check callbacks.
With 2, I mean that the problem can be in a callback! When made a command for example, which shows the player every 5 seconds a message, it can't be in the command! Check the callback (in a timer) too.
With 1, you only have to add a "print();" or SendClientMessage


I've made an vehicle pick locker. It didn't unlock the vehicle! (Example back )
So that's why I'm looking in the script. I'd search for "512". This is my result:

pawn Код:
if(newkeys & 512){
        if(IsPlayerInRangeOfAnyVehicle(playerid, 3)){
            if(IsPlayerInAnyVehicle(playerid)) return 0;
            if(PlayerAction[playerid][pHackVec] > 0) return 0;
            if(PlayerItems[playerid][pWires] <= 0) return SendClientMessage(playerid, COLOR_RED, "You don't have any wires to pick locks!");
            new Float:X, Float:Y, Float:Z;
            loop:MAX_VEHICLES(v){
                if(IsVehicleStreamedIn(v, playerid)){
                    GetVehiclePos(v, X, Y, Z);
                    if(IsPlayerInRangeOfPoint(playerid, 3, X, Y, Z)){
                        PlayerHackVec[playerid] = SetTimerEx("HackVehicle", 1100, true, "ii", playerid, v);
                        SendClientMessage(playerid, COLOR_GREEN, "* Pick locking...");
                        break;
                    }
                    else continue;
                }
                else continue;
            }
            return 1;
        }
I don't see any thing that unlocks the vehicle. So all I have to do is add it here, or look in the callback "HackVehicle", 'cuz that one is included as a timer.
This is the callback
pawn Код:
new engine, lights, alarm, doors, bonnet, boot, objective;
    PlayerAction[playerid][pHackVec]++;
    if(PlayerAction[playerid][pHackVec] == 1){
        TextDrawSetString(HackVec[playerid], "|");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
    }
    if(PlayerAction[playerid][pHackVec] == 2){
        TextDrawSetString(HackVec[playerid], "| |");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
    }
    if(PlayerAction[playerid][pHackVec] == 3){
        TextDrawSetString(HackVec[playerid], "| | |");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
    }
    if(PlayerAction[playerid][pHackVec] == 4){
        TextDrawSetString(HackVec[playerid], "| | | |");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
    }
    if(PlayerAction[playerid][pHackVec] == 5){
        TextDrawSetString(HackVec[playerid], "| | | | |");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
    }
    if(PlayerAction[playerid][pHackVec] > 5){
        TextDrawHideForPlayer(playerid, HackVec[playerid]);
        SendClientMessage(playerid, COLOR_GREEN, "* Vehicle hacked. You can now enter it");
        PlayerAction[playerid][pHackVec] = 0;
        KillTimer(PlayerHackVec[playerid]);
        PlayerHackVec[playerid] = (-1);
    }
Hmm. I can't see what's wrong yet. Let's add a ClientMessage in all the statements (idk how to call.... all the codes within the brackets). So one will look like this:
pawn Код:
if(PlayerAction[playerid][pHackVec] == 5){
        TextDrawSetString(HackVec[playerid], "| | | | |");
        TextDrawShowForPlayer(playerid, HackVec[playerid]);
            SendClientMessage(playerid, COLOR_WHITE, "[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 5");
    }
That's the ClientMessage - After checking ingame, I saw something like this:
Код:
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 1
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 2
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 3
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 4
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == 5
[DEBUG] HackVehicle(playerid, vehicleid) - pHackVec == COMPLETE
So the callback did just work! Maybe I forgot something? Yeah I did!
pawn Код:
if(PlayerAction[playerid][pHackVec] > 5){
        TextDrawHideForPlayer(playerid, HackVec[playerid]);
        SendClientMessage(playerid, COLOR_GREEN, "* Vehicle hacked. You can now enter it");
        PlayerAction[playerid][pHackVec] = 0;
        KillTimer(PlayerHackVec[playerid]);
        PlayerHackVec[playerid] = (-1);
    }
No code that unlocks the vehicle! Bug found! All you have to do is solve it.


I hope that this tutorial helped you a bit.

- Kevin
Reply


Messages In This Thread
How to find bugs - by Kwarde - 26.01.2011, 17:50
Re: How to find bugs - by Ash. - 26.01.2011, 17:53
Re: How to find bugs - by Kwarde - 26.01.2011, 17:56
Re: How to find bugs - by ricardo178 - 26.01.2011, 18:14
Re: How to find bugs - by Kwarde - 27.01.2011, 04:32
Re: How to find bugs - by Hal - 30.01.2011, 23:06
Re: How to find bugs - by Blacklite - 30.01.2011, 23:13
Re: How to find bugs - by Kwarde - 31.01.2011, 13:43
Re: How to find bugs - by Marty_Alex - 05.02.2011, 03:27
Re: How to find bugs - by Scenario - 05.02.2011, 03:35

Forum Jump:


Users browsing this thread: 1 Guest(s)