A
Andrew Cooper
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
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