PDA

View Full Version : All of your stupid embarrassing coding mistakes!


[HLF]Southclaw
04/08/2012, 06:06 PM
If you see my posts, you probably know I make a ton of stupid mistakes, then I fix them, right after posting.
Some are annoying, some are quite hilarious! But they all make me feel stupid :p



I think the most recent one was I was having problems with file loading, I noticed my money was resetting, and a bunch of other things. I got all confused and started debugging my file script thinking something was failing.

I take a look at the login function and find that I never even called "file_Open" so all the "file_Get*" functions were just returning nothing!



The remedy I use is just practice, sometimes I just code things my server might not need, such as a text replacer that replaces "#<letter>" with the NATO phonetic of that letter (#y = yankee, #n = november etc...)
What other advice for remembering things have you guys got? I'm pretty forgetful in many things, especially coding (forgetting ;, function names, parameters, variables, stupid things etc)



Anyway, enough about me being stupid, I bet all of you (even the really good ones!) have made some stupid mistakes!

Arca
04/08/2012, 06:43 PM
This mistake often happens to me.

SendClientMessage(playerid, -1, "Welcome back %s!", PName(playerid));

And also this

static health; GetPlayerHealth(playerid, health);

Always forget the tags.

Vince
04/08/2012, 07:07 PM
I hooked GivePlayerMoney to automatically increment a variable, which, when I used it to give players money upon login inadvertently doubled their money every time.

[KHK]Khalid
04/08/2012, 07:11 PM
Southclaw;2034080']What other advice for remembering things have you guys got? I'm pretty forgetful in many things, especially coding (forgetting ;, function names, parameters, variables, stupid things etc)

Commenting whatever you create? If you think you might forget what a function does or if a function needs explanation then comment it. For each function you make, leave a comment to describe the arguments and what it returns/does and once you update your code, update your comments too. Also this:


Orignially Written by WikiHow

Use consistent naming conventions for variables. It will help you keep track of each type of variable, and also what that variable's purpose is. This means more typing than simply x = a + b * c, but it will make your code much easier to debug and maintain. One popular convention is Hungarian notation (http://en.wikipedia.org/wiki/Hungarian_notation), where the variable name is prefixed with its type. For example, for integer variables you might use intRowCounter; strings might use strUserName. It doesn't matter what your naming convention is, but be sure that it is consistent and that your variable names are descriptive. (See Warnings below).


That way you will never have a problem to know what a code is written for.

Southclaw;2034080']I bet all of you (even the really good ones!) have made some stupid mistakes!

Not really, pawn is not the first programming language for some of the people here, some of them have known (I mean studied) other greater programming languages such as c, c++ or c# before pawn which makes it kind of easy to understand the pawn language when you have a good knowledge in those languages. But, yea that's true in the very very beginning of learning a programming language (Atleast for me) :) .

[HLF]Southclaw
04/08/2012, 07:21 PM
I never said only Pawn mistakes ;)

Thanks for the comment tip as well, I started doing this a while back THEN FORGOT! I must remember to do it more :p The problem is once I start doing it, I'll want to do it to ALL my code (All 30~ files of it)

Naming conventions is a good way, I use a Hungarian Notation adaptation for SA:MP and my gamemode (Variables/Functions are prefixed based on what file they are in, each feature has it's local code in a file, and if anything is used across multiple files, it's put in the global master file)



The past few days I've been REALLY confused about my custom damage script, and got annoyed with it last night, however this morning I found the player health variable was being changed on OnPlayerTakeDamage AND OnPlayerGiveDamage so it was being set twice and instant-killing people, I felt very stupid for not checking both callbacks!

Vince
04/08/2012, 08:27 PM
Fuck Hungarian Notation. I hate that whole heartedly. The compiler does the type checking so this is just dumb and useless. I could see it being used in PHP or so, which is a typeless language, but not in Pawn or C. I just can't read code that's written in HN, it makes my eyes bleed.

Bakr
05/08/2012, 04:04 AM
Fuck Hungarian Notation. I hate that whole heartedly. The compiler does the type checking so this is just dumb and useless. I could see it being used in PHP or so, which is a typeless language, but not in Pawn or C. I just can't read code that's written in HN, it makes my eyes bleed.

The whole point of Hungarian Notation is not for the compiler but the programmers; specifically the ones who didn't write the code themselves. This will allow them to more easily follow the track of variables for things like their scope and data type without having to refer back to their declaration. If you have trouble reading Hungarian Notation, you will have trouble in the more mainstream programming and projects.

As for my stupid mistakes, I often now use C functions instead of Pawn functions for things like string manipulation and file handling. It is quite annoying going from one language to the next when you have different functions that basically result in the same thing. It is even more annoying when functions have the same names, but take different parameters, return different values, or do something completely different than the one you previously knew.

leonardo1434
05/08/2012, 04:31 AM
pretty easy to forget the name of the variable's/publics/functions, Even in others languages.

Such like in c++, i'm beginner in it, but already know some cool stuff.

Misiur
05/08/2012, 06:56 AM
Once I took a job for some e-shop feature. I got home drunk, and written it, but thank God I didn't publish it. When I woke up, hangover, I looked at the code - there were 4 nested loops, and on each level there was executed query - approx 16k unnecessary queries (I fixed it, and got final result of 1 query thanks to joins and stuff). Drunk coding might seem awesome, but leads to problems. Don't drink and develop!

Joe Staff
05/08/2012, 11:23 AM
I was having a variable change by itself without ever actually being changed by a particular code.
Turns out I was using a string with too few cells, which for some reason was changing my other variables.

Universal
05/08/2012, 11:29 AM
You are not the only one, who has these stupid little mistakes. This is one of my mistakes that I usually make:

for(new i=0; i<MAX_PLAYERS; i++) {
if(IsPlayerConnected(playerid)) {
// ...
}
}

I always forget that its not playerid I should use inside the loop. :D

And for the things you want to remember, I make a to-do list above everything in the main .pwn file (ofc. its commented) and I always track this list so I can remember what I have done and what needs to be done.

IstuntmanI
05/08/2012, 11:53 AM
Southclaw;2034080']If you see my posts, you probably know I make a ton of stupid mistakes, then I fix them, right after posting.

^ This. I request help, then I fix/solve (almost everytime) it myself.

Basssiiie
05/08/2012, 11:57 AM
One I usually make:
stock Something(playerid);
{
// something here
}
There shouldn't be a ; on the after Something(playerid).. >:(

Jikesh
05/08/2012, 11:59 AM
Happens with me most of the time
SendClientMessageToAll(playerid, -1, string);

playbox12
05/08/2012, 12:14 PM
Using cache functions while having cache disabled for the query.

[HLF]Southclaw
05/08/2012, 10:30 PM
Okay, I just fixed a DAMN ANNOYING (but incredibly newbie stupid) bug.

I spent about 2 hours this morning trying to work out why file loaded vehicles weren't spawning or their coordinates weren't working in IsPointInDynamicArea.

Forgot 'Float:' on coordinate variables.



:picard:

Joe Staff
05/08/2012, 10:48 PM
Southclaw;2036665']Okay, I just fixed a DAMN ANNOYING (but incredibly newbie stupid) bug.

I spent about 2 hours this morning trying to work out why file loaded vehicles weren't spawning or their coordinates weren't working in IsPointInDynamicArea.

Forgot 'Float:' on coordinate variables.



:picard:

I get these kinds of errors when working with Java (Android OS) and kind of relating to issues I have when working with angles. Not sure if I should use radians or Euler in some maths.

Jstylezzz
06/08/2012, 12:27 AM
i make those stupid mistakes like

if(!IsPlayerInAnyVehicle(playerid,COLOR_RED,"You are not in any car"));

which has to be:

if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not in any car");


i know, this is pretty stupid :eek:

admantis
06/08/2012, 12:31 AM
I always confuse variables in loops, like this:


foreach(Player, i)
{
SendClientMessage(playerid, -1, "Some text");
}

And the player would be spammed with that text.
It really happens in an almost daily basis.

NinjaChicken
13/08/2012, 03:24 AM
i accidently created a loop, so that every 10 seconds the players cars got duped, so in about 10 minutes the server over loaded because i broke samp limits it was quite diffcult to fix as every player had about 800 cars each spawning on the same spot... caused alot of lag :)

Steven82
14/08/2012, 03:22 PM
i accidently created a loop, so that every 10 seconds the players cars got duped, so in about 10 minutes the server over loaded because i broke samp limits it was quite diffcult to fix as every player had about 800 cars each spawning on the same spot... caused alot of lag :)

Lol, I've done the same thing once but it was with an old house system I made about 2 years ago. I felt like such a n00b because the houses would load into the server and the house pickups would just keep creating and they wouldn't stop.

Calgon
14/08/2012, 05:59 PM
When a player connected to the server, their name is checked in the bans file, but I accidentally removed GetPlayerName while making an anti-hack check and about ~60 players were all kicked and falsely auto banned.

This was a few months ago, probably my most embarrassing mistake, but it was all fixed after a few minutes, luckily nothing even saved to the ban file, it just kicked everyone because it was searching the bans file for literally nothing, so it found nothing and kicked everyone who connected.

Roperr
14/08/2012, 07:12 PM
Probably the biggest mistake I made was making an infinite loop which made the CPU usage go up to 100% and crashed our old VPS we had :D

Actually I did that twice :P

ReneG
18/08/2012, 11:31 AM
enum pinfo
{
Float:pos[3];
}

new data[MAX_PLAYERS][pinfo];

// I always make this mistake.

GetPlayerPos(playerid, data[playerid][pos[0]], data[playerid][pos[1]], data[playerid][pos[2]]);

HuSs3n
20/08/2012, 11:55 PM
i once used createvehicle inside a loop
and thats the result

http://img18.imageshack.us/img18/8146/samp309x.th.png (http://imageshack.us/photo/my-images/18/samp309x.png/)

http://img341.imageshack.us/img341/4787/samp310f.th.png (http://imageshack.us/photo/my-images/341/samp310f.png/)

dumper rain :HELLYEAH:

ricardo178
20/08/2012, 11:57 PM
GivePlayerMoney(playerid +ammount); for the win....

Sinner
21/08/2012, 11:06 AM
I did this a few times:


new variable = 153;
while(variable > 0) {
// Do something here
// and forgets to decrement the variable
// infinite loop O_o
}

_Jake_
21/08/2012, 12:06 PM
I was blind with this one on my /changename


dini_Set(DataPath(location), "Admin", pData[playerid][Admin]);


i didn't knew about this so i was confuse about the result on the .ini
i check the code, i saw that it was in dini_Set, i must use dini_IntSet because pData - Admin is integer not string


another is with my saving/load pos system.

my global variable array Pos must be in float tag, i forgot to add it.
when i add SetPlayerPos(playerid, Pos[0], etc...
it endup with warning tag mismatch.

FireCat
22/08/2012, 01:26 PM
I did this a few times:


new variable = 153;
while(variable > 0) {
// Do something here
// and forgets to decrement the variable
// infinite loop O_o
}


Tipical you! :)

Kar
22/08/2012, 02:46 PM
well last night I was so dumb x_X

I was making a anti team kill and I made it check if the team who shot was the same as the rival team of the other player to not damage them :picard:

[HLF]Southclaw
22/08/2012, 03:24 PM
Haha, I did something similar once, I made weapons subtract negative damage from the target player, which healed them!

Patrik356b
22/08/2012, 03:32 PM
Not mine, but ugh:
new IconID=1;
mysql_function_query(SQL_Connection, "SELECT * FROM `icons`", true, "IconLoad", "i", "IconID");

milanosie
22/08/2012, 06:07 PM
stock ShowPlayerDialogEx(playerid, dialogid, style, caption[], info[], button1[], button2[])
{
P_Dialog[playerid] = dialogid
ShowPlayerDialogEx(playerid, dialogid, style, caption[], info[], button1[], button2[]);
return 1;
}


Now you tell me what is going to happen, I did it once-.-
dumb mistake

2KY
22/08/2012, 07:36 PM
Southclaw;2036665']Okay, I just fixed a DAMN ANNOYING (but incredibly newbie stupid) bug.

I spent about 2 hours this morning trying to work out why file loaded vehicles weren't spawning or their coordinates weren't working in IsPointInDynamicArea.

Forgot 'Float:' on coordinate variables.



:picard:

I do this constantly. lol

=WoR=G4M3Ov3r
22/08/2012, 11:44 PM
GivePlayerMoney(playerid +ammount); for the win....

I've done the same shit :p

new amount;
code
GivePlayerCash(playerid, +amount)

I forgot that GivePlayerCash was positive lol and I stayed for hours checking on what was the error due to. Found out and facepalmed.

Or I forget a ; after return