Game Development Community

Server-side Scripting Object ID Problem: Off-by-one

by DavidRM · in Torque Game Engine · 10/31/2002 (10:55 am) · 10 replies

I've run into a rather odd problem with the server-side client connection object.

I have added some scripting "data members" to the %client object to handle inventory tasks. Most of the time, there's no problem. I access the data normally (e.g., "%client.InventoryObject"). Sometimes, however, I get an error like this:

"pbn/server/scripts/inventoryGameConnection.cs (57): Unable to find object: '1463' attempting to call function 'InventoryCopy'"

What makes things puzzling is that '1463', the object ID reported, is one greater than the connection object's actual object ID as reported in the CADD and CDROP log messages:

Got Connect challenge Request from IP:...:1570
Got Connect Request
Connect request from: IP:...:1570
CADD: 1462 IP:...:1570
...
Client 1462 disconnected.
Issuing Disconnect packet.
CDROP: 1462 IP:...:1570

Each time this error has occurred, it's been off-by-one like this (one greater).

The problem shows up in the scripts which create the %client's player object for a new mission. It's like the %client object that is handed to the mission start scripting functions is different from the regular %client object.

I've also noticed that the problem doesn't seem to affect the first player that logs into the server. Or rather, the problem seems to happen only when a player logs in when there are one or more other players already logged in. It's inconsistent, though. It doesn't happen every time.

If anyone has any clues or thoughts, I'd love to hear them.

Thanks in advance.

-David
Samu Games

#1
10/31/2002 (11:01 am)
Hey David,

This doesn't quite sound like this bug... but may be worth a go:

www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=7742

Lemme know if the problem is resolved from doing this... that would prove quite interesting :)

-J
#2
10/31/2002 (2:09 pm)
It's worth looking into. Thanks for the link.

Attending the IGC this weekend, so it'll be next week before I can really start digging. Or maybe I'll stumble across someone with the answer this weekend... =)

Thanks again.

-David
#3
10/31/2002 (3:06 pm)
We've(the Legends guys') are running into the same problem.
#4
11/01/2002 (12:53 am)
That link doesn't solve the problem, it actually creates other issues when trying to extract information from mission files.

This is something that should be taken a little more seriously cause from all that I've traced through there is nothing script-wise that we've done wrong to cause this to be offset.
#5
11/01/2002 (1:29 am)
Perhaps, but it's hard to take a problem seriously before you've encountered it. I'm sure that when I encounter the problem it will be something that I will fix. Apparently nobody with the time and skill to fix it has encountered it yet.
#6
11/01/2002 (5:44 am)
David,

I apologize for being so flippant with my help... I'll try and be more serious. :)

The bug I reported to the task manager and that link remains... and is a serious one.

What Robert points out was a problem since fixed in the link I gave.

I am curious if this one off remains after making the changes I described. As I said, it doesn't quite sound like this... but improper name matching could cause such behavior.

-J
#7
11/01/2002 (6:20 am)
You may need to post how you are getting the index, is it in a for loop with the max being the client count?
#8
12/06/2002 (10:10 am)
Over a month later, I'm finally able to dig into this again. I have discovered the following:

1. It's not an off-by-one error.

2. The problem isn't with the GameConnection object. It's with an object that is tied to the GameConnection object.

NOTE: The object is usually created immediately after the GameConnection object, so it's ID is usually one greater. Hence my confusion.

3. The problem is that Sim::findObject() for the object (looking by ID) fails.

An example line that's failing:

function GameConnection::InventoryClearProperty(%this,%propertyName)
   {
   %this.InventoryObject.InventoryClearProperty(%propertyName);
   }

With the error:

pbn/server/scripts/inventoryGameConnection.cs (63): Unable to find object: '1636' attempting to call function 'InventoryClearProperty'

My new research will focus on making sure that the InventoryObject property isn't being hammered somehow. And I'm going to experiment with few levels of dereferencing in the same statement.

Thanks to everyone for their responses.

-David
#9
12/07/2002 (9:16 am)
Just to provide some "forum closure" on this: The problem has been fixed.

The downside, unfortunately, is that I'm not entirely certain what fixed it. I *think* the solution came from a bit of code re-organizing, but I'm not sure. "Re-organizing" because I didn't really change anything. In a few places, I added use of temporary variables instead of just assigning directly to object properties. And in one instance, I moved some code out of a sub-function, up a few call levels (I like it better in the new location; fits better).

Which one fixed it? Dunno. Did some of my simplistic refactoring manage to fix a non-obvious bug in my scripts? I have no idea. Is the scripting engine a bit quirky and I just bypassed one of its quirks? It's a mystery...

Thanks again to all of those who provided suggestions. I really appreciate it.

-David
#10
12/07/2002 (9:23 am)
Most code "mysteries" come back to haunt you... not all, but most...

-Joshua Ritter
ActionRPG Revolutionary