Re: Importing Custom Classes

fnl <[email protected]> Sun, 26 Apr 2015 02:17:55 -0700 (PDT)
Newsgroups gmane.comp.java.robocode
Message-ID <[email protected]>
Hi Mike,

Your myBot class must extend your myUtils, which contains your spin() 
method.
So you must write:

package mo;
import mo.myUtils;

public class myBot extends myUtils {

    public void run() { 
        while(true) {
           spin();
       }
    }    
}

Also note that your class names should not start with a small letter, but a 
big capital letter. That is a common Java convention.
So you should change 'myUtils' into 'MyUtils' and change 'myBot' into 
'MyBot' in both class files. :-)

Best regards,
- Flemming


Den søndag den 26. april 2015 kl. 11.00.29 UTC+2 skrev Mike Oliver:
>
> This may be a silly beginner question, but how do I access functions after 
> importing a custom class?  When I compile I receive 'undefined method' 
> errors. Ideally I would like to clean up my code and make it more reusable.
> Robowiki and repository are down, so my options to learn are pretty 
> limited.
>
>
> myUtils.java (compiles)
> package mo;
> import robocode.*;
>
> public class myUtils extends AdvancedRobot{
>  public void spin() {
> setTurnRight(10000);
> }
> }
>
> myBot.java (doesnt compile)
> package mo;
> import robocode.*;
> import mo.myUtils;
> import java.awt.Color;
>
> public class myBot {
>
> public void run() {
>  while(true) {
> spin();
> }
>  } 
> }
>
> Compile Error:
> Compiling...
> ----------
> 1. ERROR in D:\MyFiles\Games\RoboCode\robots\mo\MyBot2.java (at line 11)
> spin();
> ^^^^
> The method spin() is undefined for the type MyBot2
> ----------
> 1 problem (1 error)
> Compile Failed (-1)
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.