Full Version : Needing help on an error
xmlspawner >>Scripting Support >>Needing help on an error


<< Prev | Next >>

Grimhawk- 03-29-2007
Don't know if its because of lack of sleep or just over looking something but have and error I can't seem to figure out. Thank you for any help you can give.

The error is 'Server.Mobile' does not contain a definition for 'Controlled' .




CODE
           foreach (Mobile m in from.GetMobilesInRange(range))
           {
               if (m == from || m == null)
                   continue;

Error is this line -->   if (from.Controlled)
               {


ArteGordon- 03-29-2007
That is because 'Controlled' is a Basecreature property, not a Mobile property, and your 'from' variable must be declared as a Mobile.

You should first check to see if 'from' is a Basecreature, and then cast it to the proper type.

CODE

Basecreature b = from as Basecreature;

if(b != null)
{

// do your stuff
// and check for b.Controlled instead of from.Controlled

}

Grimhawk- 03-29-2007
Think I understand what you mean but I'm not sure if I do. Below is the whole section I'm working with and I'm not sure how I'd add in what you suggest.


CODE
           ArrayList targets = new ArrayList();

           foreach (Mobile m in from.GetMobilesInRange(range))
           {
               if (m == from || m == null)
                   continue;

               if (from.Controlled)
               {
                   if (m is BaseCreature && !(((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned))
                       targets.Add(m);
                   else if (m.Player && m.AccessLevel == AccessLevel.Player && m.Alive && m.Kills >= 5)
                       targets.Add(m);
               }
               else
               {
                   if (m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned))
                       targets.Add(m);
                   else if (m.Player && m.AccessLevel == AccessLevel.Player && m.Alive)
                       targets.Add(m);
               }
           }

Xarlon- 03-30-2007
change this line...
CODE
if (from.Controlled)
to this...
CODE
if (from is BaseCreature && ((BaseCreature)from).Controlled)


I'm not sure what you're trying to do... but that should get you to the next step.