0
// Check if the new position is on an arrow
foreach (Item Item in GetFloorItems())
{
    if (Item.Definition.SpriteId == 5000)
    {
        if (Actor.PositionToSet.X == Item.RoomPosition.X && Actor.PositionToSet.Y == Item.RoomPosition.Y)
        {
            Session Session = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);
            ItemEventDispatcher.InvokeItemEventHandler(Session, Item, this, ItemEventType.Interact, Actor.MoveToAndInteractData);
        }
    }
}

the error line : if (Actor.PositionToSet.X == Item.RoomPosition.X && Actor.PositionToSet.Y == Item.RoomPosition.Y)

Sorry, I'm new to C#. Had this problem before, I just can't seem to see what's wrong, Although it was on a different line, all I had to do was check if it was null, but don't see much of the same here?

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

0

This might work. Switch the if from

if (Actor.PositionToSet.X == Item.RoomPosition.X && Actor.PositionToSet.Y == Item.RoomPosition.Y)

to this:

if (Actor != null && Actor.PositionToSet != null && Actor.PositionToSet.X == Item.RoomPosition.X && Actor.PositionToSet.Y == Item.RoomPosition.Y)

When you try to look at a property of an object that is null you will get this error. The reason is that a null object has no properties (ish). If Actor is null then you can't look at Actor.PositionToSet. If Actor is not null then the property PositionToSet is something you can look at but if that is null then the properties X and Y can't be looked at. I hope that makes sense but just add comments with any additional questions.

Teeknow
  • 1,015
  • 2
  • 17
  • 39
0
if (Actor != null )
{
    if(Actor.PositionToSet != null )
    {
        if(Actor.PositionToSet.X == Item.RoomPosition.X && 
           Actor.PositionToSet.Y == Item.RoomPosition.Y) {
            // Do your stuff
        }
    }
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
anoop
  • 3,229
  • 23
  • 35