[Tutorial] How to debug.
#1

Hello, I have been looking through threads, and I came to the conclusion that it lacks of people having the actual knowledge to debug their own code.

Q: Why would I debug?
A: Debug is a good way to find whether your variables/strings are correctly.

Q: How do I debug?
A: There are multiple ways of debugging, you can either debug it with SendClientMessage's or print's.

Q: Where does it print?
A: If you use SendClientMessage it prints IG, if you are using print's it's in your samp-server.exe.

Okay, I will be using the printf function(https://sampwiki.blast.hk/wiki/Printf), let's start

How to debug integer's?

Код:
new array[3]; // Creating the array to keep the integers
Код:
array[0] = 1; // Adding a value to the arrays.
array[1] = 2; // Adding a value to the arrays.
array[2] = 3; // Adding a value to the arrays.
Код:
printf("Arr1: %d, Arr2: %i, Arr3: %d" array[0], array[1], array[2]); // Printing the code.
It will print:

Код:
Arr1: 1, Arr2: 2, Arr3: 3
So, now we've learned how to debug integers, let's step to strings.

Код:
new string[5]; // Creating a new string

string = "Text"; // Assigning a value to the string.
Код:
printf("%s", Text); // As you can see we use this time this parameter: %s because we are going to debug a string now, you can find all parameters on the wiki(https://sampwiki.blast.hk/wiki/Printf).
It would print: Text.
__________________________________________________ ___________________________________

Okay, this was the most basic stuff, now let's procceed to the more difficult one.
We will we debugging callback's now, we will start off with OnPlayerDeath.

Okay, the parameters for the OnPlayerDeath callback are: (playerid, killerid, reason).
Which means that both playerid and killerid are integer's and reason is a string.

We have learned that strings are %s and integer can either be %i or %d.

Код:
printf("OnPlayerDeath: playerid: %d, killerid; %d, reason: %s", playerid, killerid, reason); // Place this under OnPlayerDeath and it will print the data.
This is just a basic tutorial on how to debug, you can find all of the parameters at the wiki, and if you are curious and want to try out your code, use Slice's Pawn Playground(https://sampforum.blast.hk/showthread.php?tid=314780)

Did I miss something? Feel free to post it on this thread!

Usefull links:

Printf wiki
Slice's playground(Thanks!)

Thanks for your attention.
Reply


Messages In This Thread
How to debug. - by jihadmeneer - 19.05.2014, 08:50
Re: How to debug. - by superrobot48 - 21.05.2014, 17:37

Forum Jump:


Users browsing this thread: 1 Guest(s)