swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] trouble using an index


From: Scott Christley
Subject: Re: [Swarm-Support] trouble using an index
Date: Fri, 07 May 2004 19:25:56 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) Gecko/20040301

Eric,

The code looks okay; what is the return type for -getXPos and -getYPos, int or float or something else? If the compiler does not know the return type, then it may assume it is type "id" in which case putting an "id" into a float is a funky type conversion. The compiler may not know the return type if it has not seen the method defined; what class is element? I suppose you could force the conversion with:

elementX = (float)[element getXPos];

Later on in the code you use the same methods to get newX and newY, do they work fine? or do you get the same errors with those?

cheers
Scott

Eric McLeskey wrote:

First, I'm relatively new to this so please bear with me...

I'm getting a complile error while trying to so what seems to be a fairly
basic routine with a list.  (What I think I am doing...) is creating an
index and creating a generic object (element) to be assigned to each
successive item in a previously created flowfieldList.  What I've done is
very similar to what is described in the swarm user guide.  When I complile,
I get an "incompatible types in assignment" error when I try to use
"element" to access a value from the object in the list.  For example, the
following lines receive the error:

elementX = [element getXPos]
elementY = [element getYPos]

I've attached my code.  I've been staring at this for almost 8 hours trying
to figure it out and I'm close to beating my head against the wall.  I'm
running swarm 2.2 pretest 11 on windows XP using cygwin if this may be
relevant...

Thanks for any help,
Eric


-step{
id <List> nodesICanSee;
id <Index> flowfieldIndex;
id element = nil;

id <Index> localNodeIndex;
id localElement;
id idealNode;

float extentOfView = 10.5;
float xLow, xHigh, yLow, yHigh, newX, newY;
float elementX, elementY;

xLow = [brownNode getX] - extentOfView;
xHigh = [brownNode getX] + extentOfView;
yLow = [brownNode getY] - extentOfView;
yHigh = [brownNode getY] + extentOfView;

nodesICanSee = [List create: [self getZone]];
flowfieldIndex = [flowfieldList begin: [self getZone]];

while((element = [flowfieldIndex next]) != nil){
elementX = [element getXPos]; elementY = [element getYPos];
       if(elementX > xLow && elementX < xHigh && elementY > yLow &&
elementY < yHigh)
               [nodesICanSee addLast: element];
}
[flowfieldIndex drop];

localNodeIndex = [nodesICanSee begin: [self getZone]];
float nodeDepth = 1.0;

while((localElement = [localNodeIndex next]) != nil){
        if (nodeDepth < [localElement getDepth]){
               nodeDepth = [localElement getDepth];
               idealNode = localElement;
        }
}
newX = [idealNode getXPos];
newY = [idealNode getYPos];

[brownNode moveX: newX Y: newY];

return self;
}


Eric McLeskey
Graduate Student
Institute for Natural Systems Engineering
Utah State University
1600 Canyon Road
Logan, UT  84321

phone: (435) 797-8039
fax:  (435) 797-8038
address@hidden






reply via email to

[Prev in Thread] Current Thread [Next in Thread]