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

2021/2/8

Scenario doesn't run online but works fine in Greenfoot

Ayulin Ayulin

2021/2/8

#
I tried uploading this scenario but it doesn't work online (you can see for yourselves). I included the sourcecode, could someone maybe help me and tell me what's wrong. I'm rather new to Java so please excuse my bad code (especially all the unnecessary static variables).
RcCookie RcCookie

2021/2/8

#
You need to increate the world size to be able to see the full exception. These are caused because for the online page your Java source code is converted to JavaScript, and unfortunatly the converter is quite rubbish.
Ayulin Ayulin

2021/2/8

#
RcCookie wrote...
You need to increate the world size to be able to see the full exception. These are caused because for the online page your Java source code is converted to JavaScript, and unfortunatly the converter is quite rubbish.
oof that kinda sucks, as the whole game is designed for a certain size and probably won't make sense on a larger size but I'll try uploading it in 600x400
Ayulin Ayulin

2021/2/8

#
It's 1200x600 now and I still can't see the whole message, how large do I need to go?
Ayulin Ayulin

2021/2/8

#
Alright, it doesn't fit on my screen anymore but at least I can read the exception, it reads: "Exception instantiating world class: java.lang.RuntimeException - (JavaScript) Error: Invalid recorded state" Sadly I have no clue what Invalid recorded state means and the search results are also quite sparse. EDIT: I guess it's something about the audio but I can't find anything specific and I don't just want to remove the audio altogether. Any help is appreciated...
danpost danpost

2021/2/8

#
Try this in your FirstMainMenu class:
1
2
3
4
5
6
7
8
9
10
static GreenfootSound menu;
public FirstMainMenu()
{  
    super(1200, 600, 2);
    addObject(new FirstPlay(), 20,20);
    addObject(new FirstMuteMusic(),30,30);
    addObject(new FirstCredits(), 2, 37);
    menu = new GreenfootSound("songong.mp3");
    menu.setVolume(60);
    ...
Ayulin Ayulin

2021/2/8

#
danpost wrote...
Try this in your FirstMainMenu class:
1
2
3
4
5
6
7
8
9
10
static GreenfootSound menu;
public FirstMainMenu()
{  
    super(1200, 600, 2);
    addObject(new FirstPlay(), 20,20);
    addObject(new FirstMuteMusic(),30,30);
    addObject(new FirstCredits(), 2, 37);
    menu = new GreenfootSound("songong.mp3");
    menu.setVolume(60);
    ...
It actually solved the problem, thank you so much :D I don't understand why it did though, does JS have some kind of problem with me initialising menu at definition?
danpost danpost

2021/2/8

#
Ayulin wrote...
does JS have some kind of problem with me initialising menu at definition?
I believe so; but, apparently only in your initial world. I noticed you had the same music loaded several times (in different worlds). When using "static" or "public static", you only need one instance. In any of your other classes, for example,you could use:
1
FirstMainMenu.menu.playLoop();
Ayulin Ayulin

2021/2/8

#
Alright, thank you that helps to clean up the mess a bit... As a java beginner I thought that at least one instance of a class had to be active at any moment to use the functions in that class, that's why I defined the music in every world separately.
You need to login to post a reply.