23.01.2018, 18:20
Today I learned - Share your newly found knowledge!
23.01.2018, 19:25
Quote:
sizeof() counts characters and stops when it reaches the null terminator (0, '\0', EOS)
|
Код:
str[128] = "Hello"; printf("%i", sizeof(str)); //will print 128
23.01.2018, 20:21
You should never append to (or even edit) string literals. You will go out of bounds and most likely rewrite other literals.
23.01.2018, 20:58
Quote:
TIL this:
You now can use strcat with a constant string (idk if i'm correct for this name) passed as parameter. A better example: This isn't quite good because sizeof() doesn't work on this strings but it is still interesting. |
PHP код:
FunctionGetActorTextLabel(text[], length = sizeof(text))
{
strcat("YEA ->", text, length);
print(text);
}
06.02.2018, 18:23
TIL you can ignore parameters passed by reference (out parameters) by using a default value, just like you can with parameters passed by value (in parameters):
The default value can be anything, since it will be ignored anyway.
Use:
Код:
stock Float:DoSomething(playerid, &Float:a = 4.0) { a = 5.0; return 9.0; }
Use:
Код:
DoSomething(0); //Returns 9.0 new Float:a; DoSomething(0, a); //Returns 9.0 and variable 'a' contains 5.0
06.02.2018, 19:49
Quote:
TIL you can ignore parameters passed by reference (out parameters) by using a default value, just like you can with parameters passed by value (in parameters):
Код:
stock Float:DoSomething(playerid, &Float:a = 4.0) { a = 5.0; return 9.0; } Use: Код:
DoSomething(0); //Returns 9.0 new Float:a; DoSomething(0, a); //Returns 9.0 and variable 'a' contains 5.0 |
Would expect a tag mismatch with this, but this is great.
12.02.2018, 14:30
today i learned that there is not necessary to use
in your gamemode.
for example,instead of
you can simply write
PHP код:
stock
for example,instead of
PHP код:
stock GetTruckNeedTracks(playerid)
{
new truckneedtracks;
new truckskill = GetPlayerTruckSkill(playerid);
if(truckskill == 1) truckneedtracks = 35;
else if(truckskill == 2) truckneedtracks = 100;
else if(truckskill == 3) truckneedtracks = 220;
else if(truckskill == 4) truckneedtracks = 450;
return truckneedtracks;
}
PHP код:
GetTruckNeedTracks(playerid)
{
new truckneedtracks;
new truckskill = GetPlayerTruckSkill(playerid);
if(truckskill == 1) truckneedtracks = 35;
else if(truckskill == 2) truckneedtracks = 100;
else if(truckskill == 3) truckneedtracks = 220;
else if(truckskill == 4) truckneedtracks = 450;
return truckneedtracks;
}
12.02.2018, 16:19
Quote:
...
you can simply write PHP код:
|
Now, you can learn something new. It's called "switch case" statement (« tutorial here!).
PHP код:
GetTruckNeedTracks(playerid)
{
new truckneedtracks;
new truckskill = GetPlayerTruckSkill(playerid);
if(truckskill == 1) truckneedtracks = 35;
else if(truckskill == 2) truckneedtracks = 100;
else if(truckskill == 3) truckneedtracks = 220;
else if(truckskill == 4) truckneedtracks = 450;
return truckneedtracks;
}
PHP код:
GetTruckNeedTracks(playerid)
{
switch(GetPlayerTruckSkill(playerid))
{
case 1: return 35;
case 2: return 100;
case 3: return 220;
case 4: return 450;
}
return 0;
}
12.02.2018, 20:26
Quote:
There is quick tutorial to explain when you can use the keyword stock: http://forum.sa-mp.com/showpost.php?...16&postcount=1
Now, you can learn something new. It's called "switch case" statement (« tutorial here!). PHP код:
PHP код:
|
12.02.2018, 23:14
(
Последний раз редактировалось Eoussama; 14.02.2018 в 23:01.
)
Today I learned about a simple BATCH instruction that serves as a cool hack when testing/debugging.
1- First, open any text editor, and paste the following instructions
2- Save the file as “something.bat”
3- Run the .bat file
Now, whenever you change your code source and compile, no need to exit and re-execute your samp-server.exe, just type the exit command in the console, and it will automatically close and re-open it for you.
1- First, open any text editor, and paste the following instructions
PHP код:
@echo off
:s
samp-server.exe
goto s
3- Run the .bat file
Now, whenever you change your code source and compile, no need to exit and re-execute your samp-server.exe, just type the exit command in the console, and it will automatically close and re-open it for you.
18.02.2018, 21:41
Quote:
Today I learned about a simple BATCH instruction that serves as a cool hack when testing/debugging.
1- First, open any text editor, and paste the following instructions PHP код:
3- Run the .bat file Now, whenever you change your code source and compile, no need to exit and re-execute your samp-server.exe, just type the exit command in the console, and it will automatically close and re-open it for you. |
19.02.2018, 14:00
02.03.2018, 13:29
today i learned.... what means strtok
basicly strtok means
str - is a string == 1
tok - is a token == 2
strtok(const string[], &index)
1. its porpuse is to fetch textual declaration like the callback know as 'OnPlayerCommandText' with the parameters (playerid, cmdtext[])
2. tokes porpuse is to check indexe's or the given parameter of 'playerid'
here on the given example will show you how its done
example code:
basicly strtok means
str - is a string == 1
tok - is a token == 2
strtok(const string[], &index)
1. its porpuse is to fetch textual declaration like the callback know as 'OnPlayerCommandText' with the parameters (playerid, cmdtext[])
2. tokes porpuse is to check indexe's or the given parameter of 'playerid'
here on the given example will show you how its done
example code:
Код:
public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[256+1], index; cmd = strtok(cmdtext, index); if(strcmp(cmd, "/info", true : false, 5)) < bool either its true or false { return true, false; < either it returns true or false } return false; }
06.03.2018, 17:01
TIL that you can split a macro on multiple lines with '\'
PHP код:
#define add(%0,%1) ((%0)+(%1))
main()
{
printf("%i",
add(\
5\
,\
6\
)
);
}
06.03.2018, 18:15
01.04.2018, 22:46
TIL you can specify a variable width or precision by using an asterisk.
This is useful in situations where you don't want to hardcode those values.
Код:
Width: printf("%5d", 10); //prints ' 10' printf("%*d", 5, 10); //prints ' 10' printf("%5f", 3.1415926535); //prints ' 3.141592' printf("%*f", 5, 3.1415926535); //prints ' 3.141592' Precision: printf("%.5f", 3.1415926535); //prints '3.14159' printf("%.*f", 5, 3.1415926535); //prints '3.14159' printf("%.5s", "abcdefghi"); //prints 'abcde' printf("%.*s", 5, "abcdefghi"); //prints 'abcde'
02.04.2018, 10:09
YIL the internal buffer for formatting floating point numbers is 64 characters:
Should give numbers with 100 decimal places (mostly all zeros), but doesn't:
Edit:
I'll also expand on what Freaksken said (I didn't learn this today, I wrote the original code for it). You can combine variable width and precision, plus zero prefixes:
Even better, this can totally replace "substring" code:
PHP код:
new str[256];
format(str, sizeof (str), "%7.0100f", 4.4);
print(str);
printf("%7.0100f", 4.4);
Код:
4.40000009536743164062500000000000000000000000000000000000 4.40000009536743164062500000000000000000000000000000000000
I'll also expand on what Freaksken said (I didn't learn this today, I wrote the original code for it). You can combine variable width and precision, plus zero prefixes:
PHP код:
printf("%0*.*f", 3, 5, 4.4); // Gives "004.40000"
PHP код:
new str[] = "How are you?"
printf("%.3s", str[4]); // Gives "are"
02.04.2018, 10:32
Quote:
YIL the internal buffer for formatting floating point numbers is 64 characters:
PHP код:
Код:
4.40000009536743164062500000000000000000000000000000000000 4.40000009536743164062500000000000000000000000000000000000 I'll also expand on what Freaksken said (I didn't learn this today, I wrote the original code for it). You can combine variable width and precision, plus zero prefixes: PHP код:
PHP код:
|
02.04.2018, 10:39
I have no idea sorry. As I said, the "*" functionality is something I added to SA:MP's format when I was a dev. Test it and make your own TIL post!
22.06.2018, 10:11
Today I learnt that:
will output 8.
PHP код:
new array[][] = {12,13};
printf("%i", array);
« Next Oldest | Next Newest »
Users browsing this thread: 15 Guest(s)