[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
#2

Nice for new scripters
And i love your example xD
Reply
#3

I used that example a couple of days ago.
The script didn't work, it didn't show the textdraws :P - I couldn't think of something else :')
I hate it when something ain't workin'

However, thank you

This forum requires that you wait 60 seconds between posts. Please try again in 11 seconds.
Sorry but I'm gonna take a shower in 10 seconds! No really after this message I'm gonna take a nice hot shower :').
Reply
#4

JUST GREAT!
Reply
#5

Yeah I saw it... Wtf?
I don't know how that happened.....
Reply
#6

Nice job, My technique is to make a bunch of prints to see what is failing, cause i use a bunch of stocks in some commands :P
Reply
#7

Good tutorial. You should mention that when you're debugging server crashes, you should use print()'s and not SendClientMessage - client messages sometimes don't send just before a server crash.
Reply
#8

Quote:
Originally Posted by Kwarde
Default How to find bugs
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
It was already there
However, thanks everyone :P

- Kevin
Reply
#9

This was helpfull thx
Reply
#10

I don't really get the point in having a tutorial for this. When you get the code WORKING, you go in-game and do testing, unless you are a complete idiot who feels testing is a waste of time. When you test things, you usually find a bug or two; I know I do. When you have found the bug, if you know enough about scripting you should be able to determine where it originated. Script bugs are similar to cancer; they originate somewhere but may spread throughout the script and then cause things to quit working like they should. Make sense?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)