473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Object not getting set

Greetings,

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

<code>
Private Sub CmdInventory(ByVal Sender As Client, ByVal Arg As String)
'Shows the inventory of the indicated player. If the player is anyone other
than
'the Sender then the Sender must be a Wizard or Royal to see it.
Dim oPlayer As Player
Dim oTarget As Player
Dim lDBRef As Long
Dim cInv As New Hashtable()
Dim oItem As Item
Dim sMsg As New CString()
'Must be logged on.
If Sender.Status < ClientStatusEnum.LoggedIn Then
Sender.Send("You must be logged in.")
Exit Sub
End If
'If the Arg is someone other than the Sender then the Sender must be
'a Wizard or Royal.
oPlayer = cPlayers.Item(Sender.Player)
If Arg.Length > 0 Then
lDBRef = cPlayers.PlayerExists(Arg)
If oPlayer.CheckName(Arg) = False And Arg.Compare(Arg.ToLower, "me") <>
0 Then
If Not oPlayer.CheckFlag(FlagEnum.Wizard + FlagEnum.Royal) Then
Sender.Send("You cannot view another player's inventory.")
Exit Sub
Else
'Check to see if the named player even exists.
If lDBRef = 0 Then
Sender.Send("That player does not exist; therefore, his
inventory does not exist.")
Exit Sub
End If
End If
End If
Else
lDBRef = Sender.Player
End If

'Get the Inventory and construct the Message.
oTarget = cPlayers.Item(lDBRef) <<<< This line seems to be setting oTarget
to Nothing, even though in the Debugger I can see that lDBRef
is the key
to an object in cPlayers, which is a Hashtable.
cInv = oTarget.GetInventory()
sMsg.Value = bRED & oTarget.Name & " Inventory:" & vbCrLf & bBLUE
If cInv.Count = 0 Then
sMsg.Append("Nothing" & vbCrLf)
Else
For Each oItem In cInv.Values
sMsg.Append(oItem.Name & " <" & oItem.DBRef & ">" & vbCrLf)
Next
End If
sMsg.Append(WHITE)
Sender.Send(sMsg.Value)
End Sub

</code>

Any help would be appreciated.

Andrew
Nov 20 '05 #1
3 846
I just reread my post and realized that the News Reader reformatted my code
badly and that I put too much code in the post. My apologies. I've cut
down the code a bit and am going to try to format it nicely... if the News
Reader will let me do it.

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

oPlayer = cPlayers.Item(Sender.Player)
If Arg.Length > 0 Then
lDBRef = cPlayers.PlayerExists(Arg)
If oPlayer.CheckName(Arg) = False And _
Arg.Compare(Arg.ToLower, "me") <> 0 Then

If Not oPlayer.CheckFlag(FlagEnum.Wizard + FlagEnum.Royal) Then
Sender.Send("You cannot view another player's inventory.")
Exit Sub
Else

'Check to see if the named player even exists.
If lDBRef = 0 Then
Sender.Send("That player does not exist.")
Exit Sub
End If
End If
End If
Else
lDBRef = Sender.Player
End If

'Get the Inventory and construct the Message.
'This line seems to be setting oTarget to Nothing,
'even though in the Debugger I can see that lDBRef
'is the key to an object in cPlayers, which is a Hashtable.
oTarget = cPlayers.Item(lDBRef)
cInv = oTarget.GetInventory()
There we go. Much better, I hope. Any help would be greatly appreciated.

Andrew
Nov 20 '05 #2
Is Sender.Player an integer? When the items are loaded are they added to the
hashtable using an integer key? I ask because lDBRef is a Long and one of
the dangers, one that most people overlook, of using a numeric key is that:

Dim Key1 as Byte = 25
Dim Key2 as Short = 25
Dim Key3 as Integer = 25
Dim Key4 as Long = 25

are all different keys since the object that is placed in the key collection
is of a different type.

So, if you are adding an item to cPlayer with an integer key of 12345 and
later you try to retrieve that item using a long key of 12345 the Hashtable
will, quite correctly, return Nothing.

"Andrew Cooper" <ae******@earthlink.net> wrote in message
news:40**********@newspeer2.tds.net...
Greetings,

I'm running into a problem where an Object is evaluating to Nothing, even
though I'm setting it to a specific Object. Here's my code:

<snip>

Nov 20 '05 #3
"Andrew Cooper" <ae******@earthlink.net> schrieb

'Get the Inventory and construct the Message.
'This line seems to be setting oTarget to Nothing,
'even though in the Debugger I can see that lDBRef
'is the key to an object in cPlayers, which is a Hashtable.
oTarget = cPlayers.Item(lDBRef)
cInv = oTarget.GetInventory()

Do you initialize cPlayers anywhere? (cPlayers = New Hashtable)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
0
by: John Perks and Sarah Mount | last post by:
I'm talk from the point of view of descriptors. Consider a.x = lambda self:None # simple function When a.x is later got, what criterion is used to see if a class (and so the func would have...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
1
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of...
6
by: Graham Pengelly | last post by:
Hi I'll try to spell out my problem as succinctly as possible... My database has a User table, an Organisation table, a Department table and a JobType table (amongst others) The...
6
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
2
by: rocketfire97 | last post by:
I'm trying to call a COM object using C# but having no luck getting values back for passed in ref objects. I've tried the same call using VB.NET and can get data back. How would I implement the...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
0
by: =?Utf-8?B?RmFicml6aW8gQ2lwcmlhbmk=?= | last post by:
I need to access classic ASP intrinsic objects and their properties from a ..net assembly wrapped to COM. The COM .net assembly is then instanciated from a classic ASP page with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.