dimanche 18 mars 2018

Continuing to Use a Dictionary with Removed Elements

I'm using a combination of a number dictionary and a list in order to rotate through several entries, using the random function. The dictionary has a keyword attached to a number that stands for a certain amount of minutes. That number is used elsewhere in the program; since I don't want the same number to be reused, I put "dictionary.get('key')" into a new list so the numbers from the dictionaries could be used by the random function. From there, I try to delete the old item from the list. But because the entry no longer exist, it messed up everything attached to the numbers. Sorry if this all sounds obtuse, feel free to message me with more questions. Here's the code, as concise as I can get it:

poseList = createNumberDict('banana', 3);
poseList.create('dragon', 4);
poseList.create('heart', 5);

poseMins = [poseList.get('banana'),poseList.get('dragon'),poseList.get('heart')];

randMin = random(poseMins);

function pictureChange(randMin,textFill) {
    if (randMin == poseMins[0]) {
//        fill(textFill);
//        textSize(65);
//        text("Bananasana",50,85)
//        image(banana,125,125,200,200);
        poseList.remove('banana');
    } else if (randMin == poseMins[1]) {
//        fill(textFill);
//        textSize(65);
//        text("Heartopening Pose",30,85)
//        image(heartopen,125,125,200,200);
        poseList.remove('heart');
    } else if (randMin == poseMins[2]) {
//        fill(textFill);
//        textSize(65);
//        text("Dragon Pose",75,85)
//        image(dragon,125,125,200,200);
        poseList.remove('dragon');
    }




Aucun commentaire:

Enregistrer un commentaire