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

2016/5/29

Actor is modifying variable of all actors belonging to the same class, when it should just be 1. Fix?

moretinshop moretinshop

2016/5/29

#
There is 1 Actor class called "TalkMenu" and another called "Survivor". A survivor actor creates new TalkMenu's, and passes itself into the TalkMenu constructor in doing so, so the TalkMenu can reference the Survivor that was used to create it. I want it so that when the TalkMenu is removed from the game, a boolean belonging to the Survivor that was used to create the TalkMenu is set to true. However, in my code the TalkMenu sets that boolean to true for ALL of the Survivor actors in the game, and not just the one used to create it. Relevant survivor code:
    public Survivor(Controller c){
        survivorNo = survivor;
        controller = c;
    }

    private void initiateDialogue(){
        getWorld().addObject(talkMenu = new TalkMenu(controller, this), 480, 420);
    }
Relevant TalkMenu code:
    public TalkMenu(Controller c, Survivor s){
        controller = c;
        survivor = s;
    }

    if(talk menu is being removed){
        survivor.finishedDialogue = true;
        getWorld().removeObject(this);
    }    
finishedDialogue then returns true for all instances of the Survivor class.
moretinshop moretinshop

2016/5/29

#
NEVERMIND, found a rogue statement that was setting finishedDialogue to true when it shouldn't be. All fixed.
You need to login to post a reply.