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

2015/12/22

Giving values for variables into a method

Loled85 Loled85

2015/12/22

#
Hey, need a quick answer to my following problem:
public void music(int Vol){
GreenfootSound sth = new GreenfootSound(music.mp3);
sth.setVolume(Vol);
sth.playLoop();
}
public void act(){
music(/*enter Volume*/);//error code in this line, saying "cannot be applied to given types; required: int, found: no arguments;
Error is in the last line.
Super_Hippo Super_Hippo

2015/12/22

#
Write in a number there.
Loled85 Loled85

2015/12/22

#
I dont want to give a specific number yet, I want that when I "Run" it to be able to enter a number just THEN...
Super_Hippo Super_Hippo

2015/12/22

#
Don't use the 'act' method for that then. Place the following into the constructor:
int volume = Integer.parseInt(Greenfoot.ask("Music Volume? (0..100)"));
music(volume);
You need to login to post a reply.