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

2015/3/8

Having sounds stored in an arraylist

sophiaking sophiaking

2015/3/8

#
I am attempting to add sound to my game, storing the sound in an array list and playing it using a for-each loop. (i must have both these items because it required for my school project) i am having trouble getting it to work
ArrayList<GreenFootSounds> sounds = new ArrayList <GreenFootSounds>();

        for (GreenFootSounds sounds: sounds ){ //add sound 
    }
danpost danpost

2015/3/8

#
A 'for-each' loop has the format: for (ObjectType variableName : listName) where 'ObjectType' is the name of the class that is declared to be assignable to the variable 'variableName'. Issues: (1) 'GreenfootSounds' is not a valid class name unless you created a class with that name; (2) in order for the for loop to execute its code-block, the list 'listName' ('sounds', in your case') must have previously had some elements added to it; (3) you probably will not be able to get away with two variables with the same name 'sounds' (for the elements of the list AND for the list itself);
You need to login to post a reply.