This site requires JavaScript, please enable it in your browser!
Greenfoot back
HardToFindAName
HardToFindAName wrote ...

2017/2/12

Help with MouseClicked, emergency

1
2
Super_Hippo Super_Hippo

2017/2/12

#
Just change the example (100|100) to the (x|y) position you want it to be. You probably mean "to get a variable from that object". You can do it the same way as you (I) did with the variable actor1 in the world.
HardToFindAName HardToFindAName

2017/2/12

#
Super_Hippo wrote...
Just change the example (100|100) to the (x|y) position you want it to be. You probably mean "to get a variable from that object". You can do it the same way as you (I) did with the variable actor1 in the world.
I've been pestering you a lot, thank you very much, I'll be forever grateful, really :D Can you be a little more specific? So, I'll create a private variable, Actor actor1, then the function will be the same, return actor1. Then, in the object where I want to use that variable, I'll write something like this:
Actor michigan = ((Harta)getWorld()).getActor1();
        
        if (michigan!=null && variable==x)
        {
           x=70;
        }
Which will most probably not work XD because that variable "variable" should be part of that object and not the other one. Help?
Super_Hippo Super_Hippo

2017/2/12

#
Well, the world already has the method to get michigan. You don't need another method to do that. You need a method for "variable" (in the class where the variable is).
public int getVariable() {return variable;}
HardToFindAName HardToFindAName

2017/2/12

#
Super_Hippo wrote...
Well, the world already has the method to get michigan. You don't need another method to do that. You need a method for "variable" (in the class where the variable is).
public int getVariable() {return variable;}
I'm a real dummy. And how should I call the method? I'll give you the code for the object where I want it be called.
Actor michigan = ((Harta)getWorld()).getActor1();
        
        if (whatever)
        {
           x=70;
        }
Super_Hippo Super_Hippo

2017/2/12

#
I forgot that you actually have to change something now if you don't want to cast the Actor to Michigan all the time. (I assume the class name of michigan is Michigan.)
private Michigan michigan = new Michigan();

//...

public Michigan getMichigan() {return michigan;}
Then you can use this:
Michigan michigan = ((Harta)getWorld()).getMichigan();
if (michigan != null && michigan.getVariable() == x)
{
    //...
}
HardToFindAName HardToFindAName

2017/2/12

#
"cannot find symbol/method getVariable()" error So, let me get this straight. I declare in the world class
private michigan michigan=new michigan();
private florida florida= new florida();

//...

public mighican getMichigan() {return michigan;}
public florida getFlorida() {return florida;}
Then, in florida I declare a variable called variable and I declare the method
int variable=20;

//...

public int getVariable() {return variable;}
Then I go in michigan and I write this:
michigan florida=((Harta)getWorld()).getFlorida();
if (florida!=null && florida.getVariable()==20)
{
//...
}
Would that work?
HardToFindAName HardToFindAName

2017/2/12

#
HardToFindAName wrote...
"cannot find symbol/method getVariable()" error So, let me get this straight. I declare in the world class
private michigan michigan=new michigan();
private florida florida= new florida();

//...

public mighican getMichigan() {return michigan;}
public florida getFlorida() {return florida;}
Then, in florida I declare a variable called variable and I declare the method
int variable=20;

//...

public int getVariable() {return variable;}
Then I go in michigan and I write this:
michigan florida=((Harta)getWorld()).getFlorida();
if (florida!=null && florida.getVariable()==20)
{
//...
}
Would that work?
If I run that I still get the same error. What am I doing wrong?
Super_Hippo Super_Hippo

2017/2/12

#
Ok, first of all, make your class names start with an uppercase letter or this is getting very confusing. In the Florida code, add a 'private' in line 1. (Or you don't need the getter method.) Then, in the Michigan code, change the 'michigan' to 'Florida'.
HardToFindAName HardToFindAName

2017/2/12

#
IT WOOOOOORKS. THANK YOU, THANK YOU, THANK YOU!!! :DDD There are a couple of hours left before me and my classmate can send the project. I hope we win. Thank you very much! :D
Super_Hippo Super_Hippo

2017/2/12

#
You're welcome. Good luck ;)
You need to login to post a reply.
1
2