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

What is happening right now?

mehanix

reply to Hello again!

By mehanix - about 16 hours ago
I think what he means is that even though the source wasn't uploaded, since it was a jar file uploaded and viewable with a java applet viewer, if you download the jar you can "decompile" it and get the source from there (since a jar is pretty much a zip archive with the code and some other stuff on top). Am i right @jetlennit? I am on the same journey btw lol with reviving/looking at old projects. I did know how to use github(barely) so i had the source saved, just never uploaded the project because i did file-based score tracking. I upgraded it to the latest greenfoot, fixed it since i know how to code now and uploaded it recently. 10 years have passed since my very first complete project which i just uploaded here. Thank you danpost, you've helped me back in the day too, I'm a software engineer now and pretty much started with greenfoot!
lmoellendorf

reply to Black screen with truncated error: "lass: java.lang.RuntimeException - (JavaScrip"

By lmoellendorf - 6 days ago
To track down the cause of the `RuntimeException` I added some `System.out.println("start of Intro()")` statements to the constructor of my initial world class. They should have shown up in the browser console. But they did not. So I figured the issue must be in the static code of my initial world class. By trial and error I found out it was the `static final` keywords for the world background `GreefootImage` and GreenfootSound`. Here is a diff: <Code Omitted> I don't understand why those `static final` are an issue especially since they work well elsewhere. But nevertheless, I was some step further. In order to even come so far, I had to find out and fix some other restrictions of the HTML5 runtime. First I had to remove dependencies to java.nio.* and java.awt.*. For example, to open files I had to use `InputStream` instead of `Files.readString()` Here is a diff: <Code Omitted> In my local version I used `Desktop.getDesktop().browse(uri)` to allow the user to open links to used artwork in my "Credits" view. I had to drop this completely, because it is not possible to open links in HTML5. And it is even not possible to have code depending on the runtime environment. Say to support opening links in the local Greenfoot environment and to drop this support only in HTML5 environment. And there were more issues to solve. In Greenfoot you can use "Set image..." in the class view to assign an image to a class. But this image is not picked up in the HTML5 runtime. Here is a diff showing what I had to change: <Code Omitted> Also I learned that `UserInfo.getMyInfo()` returns `null` if the player is not logged in. So I had to fix a null pointer exception: <Code Omitted> A very important lesson I learned is: Do not block! In local Greenfoot, waiting for `Greenfoot.isKeyDown()` in a while loop works because the simulation runs on a separate thread. In HTML5, there is only one thread — the simulation loop itself. So the while loop blocks everything, `isKeyDown()` never updates, and the loop never exits → browser timeout. Here is how I solved it: <Code Omitted> You can find my code and all changes in my Gitlab repository