swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] Discrete2d peculiar behavior


From: Paul Johnson
Subject: Re: [Swarm-Support] Discrete2d peculiar behavior
Date: Tue, 26 Oct 2004 01:49:32 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

Remember this is C. If you access an array at -1 or N, you get whatever crap happens to be sitting in memory there. So sometimes you get a non-nil piece of nonsense. I've done it and it is really hard to bug shoot.

And, when you are doing the "look one on the left and one on the right" kind of thing, you always have to make sur eyou are inside the boundaries, 0 and N-1 are the edges, and you can get gibberish if you go outside.

pj


Alex Olivas wrote:
I found the problem so my last post can be neglected.
It turns out the problem was getting objects near the boundaries
(i.e. negative values for x and/or y).  My code lookes like...


 int deltaX,deltaY;
 for(deltaX=-1;deltaX<=1;deltaX++)
   for(deltaY=-1;deltaY<=1;deltaY++)
     if((deltaX!=0)||(deltaY!=0))
   if([world getObjectAtX: xPos+deltaX Y: yPos+deltaY]!= nil){
     printf("x: %d y: %d\n",xPos+deltaX,yPos+deltaY);
     xprint([world getObjectAtX: xPos+deltaX Y: yPos+deltaY]);

My code would crash at the last line above (the xprint statement).
I was wondering if x=-1 (for example) why does [world getObjectAtX: xPos+deltaX Y: yPos+deltaY]
return a non-nil value?

This is a hack of heatbugs, so world is a Grid2d object and the space contains modified heatbugs.
Thanks,
Alex.
_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support


--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700


reply via email to

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