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

2018/4/22

.equal and ==

1
2
Lavenger Lavenger

2018/4/22

#
Quick question: why is my code not returning true when i use .equal or == for images?
1
2
3
4
5
6
7
8
9
10
11
12
//above all world class contructor
    private Actor ShadowPoseChoice = new SimpleActor(), PoseChoice = new SimpleActor();
    private GreenfootImage UmarunPose1 = new GreenfootImage("UmarunPose1.png"), UmarunPose2 = new GreenfootImage("UmarunPose2.png"), UmarunPose3 = new GreenfootImage("UmarunPose3.png"), UmarunPose4 = new GreenfootImage("UmarunPose4.png"), UmarunPose5 = new GreenfootImage("UmarunPose5.png");
 
//some code to determine what image ShadowPoseChoice is supposed to be
 
//In world class constructor
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UmarunPose1);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UmarunPose2);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UmarunPose3);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UmarunPose4);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UmarunPose5);}
danpost danpost

2018/4/22

#
Lavenger wrote...
Quick question: why is my code not returning true when i use .equal or == for images? << Code Omitted >>
Show your attempted comparison code. And, is it located in the same class?
Lavenger Lavenger

2018/4/22

#
danpost wrote...
Lavenger wrote...
Quick question: why is my code not returning true when i use .equal or == for images? << Code Omitted >>
Show your attempted comparison code. And, is it located in the same class?
1
2
3
4
5
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UmarunPose1);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UmarunPose2);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UmarunPose3);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UmarunPose4);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UmarunPose5);}
and yes it is all in the same class
danpost danpost

2018/4/22

#
Sorry I didn't catch that the first time (the fact you had already posted that which I subsequently asked for). Please show your entire constructor block.
Lavenger Lavenger

2018/4/22

#
danpost wrote...
Sorry I didn't catch that the first time (the fact you had already posted that which I subsequently asked for). Please show your entire constructor block.
here you go:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public Minigame3()
{
    //world size and back ground set up
    super(600, 400, 1);
    ArrayList<GreenfootImage> ShadowPosePool = new ArrayList<GreenfootImage>(); // for all 5 images
    for (int i=0; i<5; i++) // loop to load images into array
    {
        ShadowPosePool.add(new GreenfootImage("UmarunShadowPose"+(i+1)+".png"));
    }
    ArrayList<GreenfootImage> ShadowPoseImages = new ArrayList<GreenfootImage>(); // for 3 picked images
    for (int i=0; i<3; i++) // loop to assign 3 different random images to 3 new ShadowPoseActorss
    {
        ShadowPoseImages.add(ShadowPosePool.remove(Greenfoot.getRandomNumber(ShadowPosePool.size()))); // transfer one random image between lists
        Actor ShadowPoseActors = new SimpleActor();
        ShadowPoseActors.setImage(ShadowPoseImages.get(i));
        ShadowPoseActors.getImage().scale(100, 100);
        addObject(ShadowPoseActors, 120+180*i, 133);
    }
    //setting the "actual" image of the pose choice and add the graphical image of the pose choice into the world
    ShadowPoseChoice.setImage(ShadowPoseImages.get(Greenfoot.getRandomNumber(ShadowPoseImages.size())));
    addObject(PoseChoice, 300, 266);
    //to change the shadow image to colorized image
    if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UP1);}
    if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UP2);}
    if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UP3);}
    if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UP4);}
    if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UP5);}
}
danpost danpost

2018/4/22

#
Aren't you getting an error message for each symbol not found for variables UmarunShadowPose1 through UmarunShadowPose5?
Lavenger Lavenger

2018/4/22

#
danpost wrote...
Aren't you getting an error message for each symbol not found for variables UmarunShadowPose1 through UmarunShadowPose5?
no, since i have declared them inside of the class but outside of the constructor i have also declared the following 2 actors there as well: ShadowPoseChoice and PoseChoice
danpost danpost

2018/4/22

#
Lavenger wrote...
no, since i have declared them inside of the class but outside of the constructor i have also declared the following 2 actors there as well: ShadowPoseChoice and PoseChoice
Please show code.
Lavenger Lavenger

2018/4/23

#
this is the code that declares the 2 actors
Lavenger wrote...
1
2
3
//above all world class contructor
    private Actor ShadowPoseChoice = new SimpleActor(), PoseChoice = new SimpleActor();
    private GreenfootImage UmarunPose1 = new GreenfootImage("UmarunPose1.png"), UmarunPose2 = new GreenfootImage("UmarunPose2.png"), UmarunPose3 = new GreenfootImage("UmarunPose3.png"), UmarunPose4 = new GreenfootImage("UmarunPose4.png"), UmarunPose5 = new GreenfootImage("UmarunPose5.png");
if you're asking for the entire class code, here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import greenfoot.*;
import java.util.ArrayList;
public class Minigame3 extends World
{  
    //Actors to be in the world                                                                                                                                                                                                   */
    private Actor ShadowPoseChoice = new SimpleActor(), PoseChoice = new SimpleActor(); // the ShadowPoseActors to be with a duplicate image;
    private GreenfootImage UmarunShadowPose1 = new GreenfootImage("UmarunShadowPose1.png"), UmarunShadowPose2 = new GreenfootImage("UmarunShadowPose2.png"), UmarunShadowPose3 = new GreenfootImage("UmarunShadowPose3.png"), UmarunShadowPose4 = new GreenfootImage("UmarunShadowPose4.png"), UmarunShadowPose5 = new GreenfootImage("UmarunShadowPose5.png"), UP1 = new GreenfootImage("UmarunPose1.png"), UP2 = new GreenfootImage("UmarunPose2.png"), UP3 = new GreenfootImage("UmarunPose3.png"), UP4 = new GreenfootImage("UmarunPose4.png"), UP5 = new GreenfootImage("UmarunPose5.png");
    public Minigame3()
    {
        //world size and back ground set up
        super(600, 400, 1);
        ArrayList<GreenfootImage> ShadowPosePool = new ArrayList<GreenfootImage>(); // for all 5 images
        for (int i=0; i<5; i++) // loop to load images into array
        {
            ShadowPosePool.add(new GreenfootImage("UmarunShadowPose"+(i+1)+".png"));
        }
        ArrayList<GreenfootImage> ShadowPoseImages = new ArrayList<GreenfootImage>(); // for 3 picked images
        for (int i=0; i<3; i++) // loop to assign 3 different random images to 3 new ShadowPoseActorss
        {
            ShadowPoseImages.add(ShadowPosePool.remove(Greenfoot.getRandomNumber(ShadowPosePool.size()))); // transfer one random image between lists
            Actor ShadowPoseActors = new SimpleActor();
            ShadowPoseActors.setImage(ShadowPoseImages.get(i));
            ShadowPoseActors.getImage().scale(100, 100);
            addObject(ShadowPoseActors, 120+180*i, 133);
        }
        //setting the "actual" image of the pose choice and add the graphical image of the pose choice into the world
        ShadowPoseChoice.setImage(ShadowPoseImages.get(Greenfoot.getRandomNumber(ShadowPoseImages.size())));
        addObject(PoseChoice, 300, 266);
        //to change the shadow image to colorized image
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UP1);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UP2);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UP3);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UP4);}
        if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UP5);}
    }
    public void act()
    {
        //to check whether the  pose you clicked is right or wrong and to reward for the decision made
        if (Greenfoot.mouseClicked(null))
        {
            Actor mouseActor = Greenfoot.getMouseInfo().getActor();
            if (mouseActor != null && mouseActor.getImage() == ShadowPoseChoice.getImage()) removeObjects(getObjects(Actor.class)) /*add Yen here*/;
            if (mouseActor != null && mouseActor.getImage() != ShadowPoseChoice.getImage()) removeObjects(getObjects(Actor.class));
        }
    }
}
danpost danpost

2018/4/23

#
Explain which actors are ShadowPoseChoice and, PoseChoice. Where do they come in as far as when constructing the world? Currently, I do not see where PoseChoice is given an image. I have, however, found the main issue; but, it will take a bit of doing to get things right. You will most probably still have some other issues unless I can understand exactly what goes on with these two actors and how they fit into your scenario. One other thing that seems odd -- why would you want to change the image in the constructor of an actor after it was already set in the constructor?
Lavenger Lavenger

2018/4/23

#
danpost wrote...
Explain which actors are ShadowPoseChoice and, PoseChoice. Where do they come in as far as when constructing the world?
The ShadowPoseChoice is used to detemine which pose is the user supposed to choose from the 3 ShadowPoseActors given as a choice. The PoseChoice is used to let the user see the "colored" image of the ShadowPoseChoice simply put, PoseChoice is the graphical version of ShadowPoseChoice that's placed in the world while ShadowPoseChoice is an actor used to determine things from the code but not placed in the world.
danpost wrote...
Currently, I do not see where PoseChoice is given an image.
it's in line 30-34
Lavenger wrote...
1
2
3
4
5
6
//to change the shadow image to colorized image
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UP1);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UP2);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UP3);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UP4);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UP5);}
danpost wrote...
One other thing that seems odd -- why would you want to change the image in the constructor of an actor after it was already set in the constructor?
what do you mean?
danpost danpost

2018/4/23

#
Lavenger wrote...
<< Quote Omitted >> it's in line 30-34 << Quoted Code Omitted >> << Quote Omitted >> what do you mean?
Sorry, another oversight.
Lavenger Lavenger

2018/4/23

#
danpost wrote...
Lavenger wrote...
<< Quote Omitted >> it's in line 30-34 << Quoted Code Omitted >> << Quote Omitted >> what do you mean?
Sorry, another oversight.
It's okay
danpost danpost

2018/4/23

#
Lavenger wrote...
The ShadowPoseChoice is used to detemine which pose is the user supposed to choose from the 3 ShadowPoseActors given as a choice. The PoseChoice is used to let the user see the "colored" image of the ShadowPoseChoice simply put, PoseChoice is the graphical version of ShadowPoseChoice that's placed in the world while ShadowPoseChoice is an actor used to determine things from the code but not placed in the world.
So, really, the only thing you need to retain is which actor is supposed to be clicked on? Does that make sense? I mean, there is one specific actor the user is supposed to click on -- right?
Lavenger Lavenger

2018/4/23

#
danpost wrote...
Lavenger wrote...
The ShadowPoseChoice is used to detemine which pose is the user supposed to choose from the 3 ShadowPoseActors given as a choice. The PoseChoice is used to let the user see the "colored" image of the ShadowPoseChoice simply put, PoseChoice is the graphical version of ShadowPoseChoice that's placed in the world while ShadowPoseChoice is an actor used to determine things from the code but not placed in the world.
So, really, the only thing you need to retain is which actor is supposed to be clicked on? Does that make sense? I mean, there is one specific actor the user is supposed to click on -- right?
yes, out of the 3 actors that are dark grey in color, one will be the right one when clicked on, whilst the other two would be the wrong choice. the colored actor is just for the user to see and pick the one that is the most similar to it. but that isn't the problem, i have that working just fine, the actual problem is this part of the code here:
1
2
3
4
5
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose1)){PoseChoice.setImage(UP1);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose2)){PoseChoice.setImage(UP2);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose3)){PoseChoice.setImage(UP3);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose4)){PoseChoice.setImage(UP4);}
if(ShadowPoseChoice.getImage().equals(UmarunShadowPose5)){PoseChoice.setImage(UP5);}
it doesnt seem to be returning true no matter what, even though I have ran test runs over 50 times on it
There are more replies on the next page.
1
2