A Brief Peek Into The Mind Of A Coder

28 05 2009

So, I have the Team Fishing Contest concept. And it was all done, it was working, everything was great, then suddenly BAMMO, a team vanished from the middle of the contest and everything went splat. I let it sit for weeks because I had bigger problems to deal with, but tonight I ran more tests and finally found the cause.


— 27 list items
8, Bailers, 1, Carla Chandrayaan, eb4790f0-9c9c-4455-a709-0fd6fb0d4756, , 00000000-0000-0000-0000-000000000000, , 00000000-0000-0000-0000-000000000000
2, Green, 1, Mik Mandelbrot, 5cf06dc1-e5ba-489d-8176-6ba5e9f5cbec, , 00000000-0000-0000-0000-000000000000, , 00000000-0000-0000-0000-000000000000
0, Red, 1, Seven Shikami, 41f2bc6e-2efd-43c2-9d6c-539dd4c170a6, , 00000000-0000-0000-0000-000000000000, , 00000000-0000-0000-0000-000000000000
## Mik Mandelbrot left a team
## team leader only one left; team collapsed

— 18 list items
8, Green, 1, Mik Mandelbrot, 5cf06dc1-e5ba-489d-8176-6ba5e9f5cbec, , 00000000-0000-0000-0000-000000000000, , 00000000-0000-0000-0000-000000000000
0, Red, 1, Seven Shikami, 41f2bc6e-2efd-43c2-9d6c-539dd4c170a6, , 00000000-0000-0000-0000-000000000000, , 00000000-0000-0000-0000-000000000000

What was destroyed? List items 1-9. What should have been destroyed? List items 9-17.

Code:
integer i = llListFindList(teams,[name]);
debugspam(name+” left a team”);

if ((i-3) % 9 == 0) // uhoh, captain’s bailing
{ i = i/9;
if (freeslot(i) != 0) // team wipeout; nobody would be left
{ teams = llDeleteSubList(teams,i,i+8);
sendim(13,id);
debugspam(“team leader only one left; team collapsed”);
return;
}
…etc.

Step through it. We find the name. i=12.
if ((12-3) % 9) == 0… 9 % 9 = 0… yep, captain.

i = i/9 = 12/9 = 1
Delete sublist 1,9. WRONG! GAH! You’re mixing up LIST INDEX and TEAM POSITION!
So, instead, delete sublist i * 9, (i * 9) + 8. That’d give us 9 and 17. Good!

Another example under i*9 rules: What if Seven was quitting? That’s 21.
21-3 = 18 % 9 = 0, so captain.
i = i/9 = 21/9 = 2
2 * 9, 2 * 9 + 8 = 18, 26. Is that right? Yes!

Fixed code: teams = llDeleteSubList(teams,i * 9, (i * 9) + 8);

DONE. See, this is what happens when I hack the list directly dirty-style instead of running it through my various data grab/store functions to modify the list indirectly.

Advertisements

Actions

Information

7 responses

29 05 2009
Anonymous

Well, you did name a non-trivial variable “i”… :P

29 05 2009
doxxxicle

Dude… the magic numbers… >_<
And yeah, I’d agree that a little abstraction may help prevent this sort of problem in the future.
I don’t suppose you’re able to write unit tests for this stuff, are you? Does the environment support that sort of thing?

29 05 2009
Stefan "Twoflower" Gagne

i in my vernacular’s short for index. Problem was I was using it in the wrong way.
Since I’m the only one who ever looks at this code I rarely bother with programmer niceties and clean formatting. Bad practice, I know, but eh.

29 05 2009
Stefan "Twoflower" Gagne

I can USUALLY unit test, but this one’s a unique situation; in order to test the functionality I need a bunch of people fishing in a contest. It can’t take ‘fake fishers’ very well due to the nature of object communication in SL.
But yes, abstraction is the key. All the abstracted functions I’ve got in there right now are fine; the failure points are in the structures that CALL the abstractions having game flow errors — today for instance I found out you can invite someone to a team even if they’re already ON a team because I forgot to check for someone doing that. The actual abstract function to wrangle the teams works fine, but it needs to, y’know, be called responsibly.

29 05 2009
doxxxicle

Well, your abstracted functions should be checking for stuff like that, to avoid that exact problem.
Anyway, not gonna bust your balls over this, I’m just glad that you’re aware of things like abstraction and unit testing. :)

30 05 2009
delfina

Hey, a Cara Heron on SL contacted me. She’s been trying to rent a parcel and actually did rent it, but since she’s not in the main group she can’t rez anything and she can’t get rid of the stuff the former renters had left. She contacted Seven Shikami and Jen Shikami but no response. I can’t invite her to the group or anything, I told her to try Takamura Keiko, Meissa or Flotsam Skytower since I saw them as officers in the group. I also gave her a 50L refund for her rent, she seemed irritated but I think she’s calmed down now.

30 05 2009
jengagne

Hi Delf — yeah, she’s set up already actually. Thanks! I’ll send you $50. :D

Post a comment on this entry! All feedback welcome.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: