Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 robocode loop help...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hackmaster




PostPosted: Sun Jul 08, 2007 7:19 pm   Post subject: robocode loop help...

Hi All...wow... first post in a long time.

I need some java help. I'm new to it, although I'm fairly sure I've got this right (apparently not...)

there is a game on the web called robocode. it's a fantastic game to teach the use of java coding. it uses objects, classes, and everything that goes with that, plus it uses event based stuff as well.

I'm dealing with an event based thing here... and you don't really need to know what it does if you don't but for some reason, it doesn't want to enter the for loop I've set up.

code:



        public void onScannedRobot(ScannedRobotEvent e) {

                //out.println("I've seen a bot");

                for( int i=0; i > 10; i++ ) {

                        //out.println("I've gotten into the loop");

                        if (names[i] == e.getName()) {

                                scanned = true;
                        //      out.println("the name's a match and I've set scanned to true.");

                        }
                }

                if (scanned) {

                        return;
                }

                else {
                       
                botCount++;
                temp = e.getName();

                //out.println("I think the name I have gotten is " + temp);

                names[botCount-1] = temp;

                //out.println("I think the name in names[botCount-1] is " + names[botCount-1]);

                out.println( names[botCount-1] + " found. current bots in the arena: " + botCount);

                }


so... all the things I've commented here are my own indicators to figure out what's happening. I've discovered that my problem is that I don't even enter the loop. apparently, it's like it's not even there.

By the way, "scanned" is a global boolean that essentially means, I've already seen you, so I don't want to count you in my array again.

my goal here is to, on seeing a robot, check that it's name isn't in my array already. assume, also, that the names of my calls are all right. if it is, I give it the scanned status. then, a later if kicks it out of this function.

if it isn't already in my array, then I put it there, and add one to botCount, which is the variable I use here to represent how many bots there are.(duh)

I think my logic is all right, I just think it's not entering the for loop for some reason. any help would be GREATLY appreciated. thanks a lot!
Sponsor
Sponsor
Sponsor
sponsor
PaulButler




PostPosted: Sun Jul 08, 2007 8:37 pm   Post subject: RE:robocode loop help...

Java:

for( int i=0; i > 10; i++ ) {


The condition for the loop is i > 10, but you set i to 0 so I is never > 10. I think you meant to write

Java:

for( int i=0; i < 10; i++ ) {
Hackmaster




PostPosted: Sun Jul 08, 2007 9:09 pm   Post subject: Re: robocode loop help...

Oh my god... I'm such an idiot... Embarassed

oh well. at least my errors are always the stupid ones, and not huge faulty logic errors.

thanks a lot. (can't believe I flipped an angle bracket Smile )
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: