Scripting "Headdesk" Moments!

Nightmist

Member
Well I suppose this could be put in the general section if anyone feels it should be in there since it doesn't have to really do with anything productive... just embarrassing//annoying headdesk moments in scripting!
Just wondering if anyone has those moments ;) Feel free to share if you do.

A recent moment to share with you, this happened while I was writing up that update to my "TradeBot" script... EVILLL :mad:

KolMafia Version: 9.3 Official Release.
Script: TradeBot.ash
Heh... well I just spent easily upto 30 minutes trying to debug this thing here...
Code:
void FailResponse( OfferNum, OfferPlayer)
Mafia was throwing me the error:
Code:
')' Expected at line 1 in file
Line 1 because I separated the whole function and stuck it into a new file after about 20 minutes of failing to figure out what was wrong with it...
... xD yeah I can NOT believe it took me that long to realise I was missing the "string" and "int" in it...

Fixed Code:
Code:
void FailResponse( string OfferNum, int OfferPlayer)
0_o I repeat... EVILLL :D (Heheh but funny in the end)


PS. No I don't want the error message changed, it's incredibly obvious once you have the line singled out... well its usually obvious... >> 2, 3 hour exams kill my brain... XD Besides there wouldn't be amusing headdesk moments if all the debug messages were perfect =D , and personally headdesk moments are exactly what I need after a long stretch of coding >> Helps with remembering simple mistakes more then a accurate error in my opinion and plus it's highly amusing once you figure it out ;).

So once again, I encourage people to post their own "Headdesk" moments here!
 
A script I was recently writing: http://kolmafia.us/index.php/topic,527.msg2559.html#msg2559

originally started out:
Code:
outfit[int] gear;

and there was a call to:
Code:
if(gear[a] != $outfit[none])

we must not forget the 28 lines similar to:
Code:
gear[1] = $outfit[Bugbear Costume];

There is no $outfit type, and functions using the "outfit type" use a string parameter.

and the fact that I couldn't find any outfit_to_vartype(outfit) on the wiki so I was going to make a note of that in the message posted.

The script was complete when I realized...so yeah I had one of those moments like a few minutes ago.

Edit: my sisters kolmafia (non-scripting) "Head-desk moment"
Most mornings my sister (who lives down the road from me) wakes up before her kids get up and logs on to kol via kolmafia. She plays the game for a while, and then gets her kids up for school. I shortly arrive to take her and her kids (along with mine) to the bus stop to catch the bus. This morning she forgot to log out of kol, and close kolmafia. She came to my place after the kids went to school, and tried to log onto kol using kolmafia on my computer. Kolmafia kept logging in, then having to time the session in. For 20 minutes we tried to figure out what was going on. In firefox and IE we would log in, but before we could do anything we would get kicked back to the login page with an error "invalid session ID. Finally I did a /whois from my account and found that she was online, and she realized that she had left her account logged on at home and kolmafia was timing her session back in there.
 

holatuwol

Developer
I should share some of my debugging stories, too.  Although, I think I've purposefully tried to forget most of them, so I'll share my latest experience.

A few nights ago, I was talking to macman104, who indicated that Numfar wanted to talk to me about something mafia-related.  And so got went into a discussion and I came up with a brilliant idea to replay the combat as KoLmafia's executing a consult script in timesteps. This would make custom combat in-browser a lot friendlier, AND it would help Numfar's script.  It turned out to be a way cool feature addition, and it's tempting to me to actually use custom combat instead of LTS and KoL-side default actions.

Anyway about 15 minutes into implementing, I'm ready for the preliminary bugtest, and every time I click on the custom combat button, my web browser hangs.  Several minutes of repeated clicking, dumbfounded staring, etc. commences.  I spent time debugging the request handling, the fight handler, the proxy server that serves as the core of the relay browser, and turned up absolutely nothing. Where's that infinite loop!?

Then I look at the queue handler and discover that the code that queues stuff up was getting skipped because of a boolean check which always evaluated to true because ... I never reset the variable to false like I was supposed to before doing queueing.  So this results in the classic consumer/provider problem, this time the consumer waiting for something to eat that the provider never provides.  *headdesk* See, this is why they make you take operating systems...
 
I've got another one for you...
I was working on one of my trade scripts and it was getting stuck in an infinite loop which I could not find. to make matters worse, I was watching it in the gcli window, and could not get the window to repaint itself when switching to the adventure pane to press stop all so All I could do was end task making it more difficult to debug.

I ended up with code like this:
Code:
print("printing offered items:");
count = count - 1;
while(count != -1)
 {
 print(offerlist[count]);
 count = count - 1;
 bcounter = bcounter + 1;
 if(bcounter == 50)
  {
  cli_execute("we are stuck in an infinite loop again");
  } 
 }
where bcounter is a global variable, and "we are stuck in an infinite loop again" is simply a command to send kolmafia into error state.

upon running the script again I saw "printing offered items:" being printed repeatedly! The error was around 3000 characters away from where I was trying to find it. I finally found it...
Code:
while(count != -1)
 {
 parse_individual_trades(responselist[count]);
 }
Headdesk!

edit: btw it only took me 13 hours to find.
 

Metraxis

Member
While working on my magnum opus, the 20k and growing 'Agent' script, I would always run into a problem at about Level 6, when it would attempt to visit the shore and pick up the dingy plans, then head on to the Pirate Cove for the outfit. The problem turned out to be that I had copied the wrong kind of goal (A custom data type) and had left out a member.

Copied from:
Code:
goal Harem;
Harem.type = "IA";
Harem.ItemList[$item[harem veil]] = 1;
Harem.ItemList[$item[harem pants]] = 1;
Harem.area = $location[Knob goblin Harem];

Copied and changed to:
Code:
goal Planks;
Planks.type = "IT";
Planks.total = 1; < -- this is the bit I left out
Planks.ItemList[$item[dingy planks]] = 1;
Planks.ItemList[$item[dingy dinghy]] = 1;

As a result of the omission, the goal was satisfied as long as I had at least zero of the items in the map. *headdesk*
 
My head hits my desk again :(

This time I'm not writing a script, but it definately relates

I'm working on a program in the pascal language using the copy command which is very similar to the substring command in ash. The difference is that while the substring ash function's format is string substring( string Text, int StartFrom, int EndAt) pascal's copy functions format is copy( string Text, int StartFrom, int count) where count is the number of characters to copy. for quite some time now I have been trying to figure out why when copying substrings I was getting extra characters on the end. Turns out I was trying to use ash type parameters for substring on the pascal copy function.
 
[quote author=Metraxis link=topic=528.msg2706#msg2706 date=1162541240]
More to the point, what has possessed you to do a project in Pascal, of all languages?
[/quote]
Probably the fact that a few years ago my dad wanted Paradox 9, but couldn't find it. He bought Delphi, and didn't like it so he gave it to me, and after a little studying I found that I could understand it easily so I studied more. (That's how I first started writing programs)

There are many languages to work with, but since this sight deals with kolmafia which is written in Java, I will point out the most obvious difference between the 2. Java programs are actually just scripts which run in an interpreter which runs in windows. In pascal, the program is compiled into code which is interpreted by windows thus the end result is a faster program. On the down side I won't be taking 1 executable file and hopping from Windows to Unix to Macintosh because it requires a separate build for each OS. I don't plan to even make the source multi-platform compatible because there is really no need in this instance.

Now for the less obvious: My project is a small machine automation program which requires direct access to the individual bits on the parallel port. Since I've already done this in pascal before when I was learning to write programs and successfully controlled an LCD via the parallel port, it was an obvious choice because in a lot of cases I can just recycle code. The end result will be a basic program which I can write instruction sets for that will control small machines which I will build this winter with my son out of pieces of old toys and electronics and such so he can watch them running and see how they work.

Programmers often find flaws in a language which are not really there. Generally when that happens the programmer just hasn't taken the time to learn how to do what they need/want to do in that language. Most of the time this happens because they already know how to do what they want in another language or already have the base code written. Yes, that is both an admission of guilt and a finger pointing at the same time. :D
 
Top