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

What is happening right now?

danpost

reply to Hitting Walls

By danpost - 20 minutes ago
CosmicCaleb wrote...
I'm pretty new to this, so that sounded like Spanish. Could I have some code to see what you mean?
A field is a variable that is declared within a class, but outside of any code blocks. A variable declared within a code block only exists during the execution of the block. Once an execution block terminates, variables declared within the block no longer exist. Example 1: <Code Omitted> Example 2: <Code Omitted> Example 3: <Code Omitted>In example 3, each actor will have its own speed value. That is, line 6 will only increase the speed of one actor (the actor that the method was called on) -- not all actors of its type. Notice that the variable is declared in the block of the class -- not in an executable code block (constructor or method). Example 4: <Code Omitted>In example 4, all actors of the class' type will move at whatever value the speed variable is set to when acted on. The value is initially set when the project is compiled and does change when the project is reset. Therefore, it must be initially set (or reset) by code in the world constructor: <Code Omitted>
nccb

reply to I canĀ“t save my world :(

By nccb - about 9 hours ago
We've now replicated such an issue and fixed the bug ready for 3.5.1. Try the following to see if it also fixes the issue for you -- open your world class editor, then go to the very end of the class, and press return a couple of times to add a blank line at the end. The bug we found seemed to relate to the lack of a newline at the end of the file confusing the editor.
danpost

reply to Spawn objects faster the less objects of that kind are in the world

By danpost - about 23 hours ago
You can base the random chance to spawn on the number of rocks currently in the world. For example, line 3 could be: <Code Omitted>
danpost

reply to How can I save and read a highscore?

By danpost - about 23 hours ago
There seems to be several issues with the given code. I cannot positively say that any are directly related to your current issue. (1) You should only need to get the UserInfo object once -- not every act cycle; and certainly not twice every act cycle, which is what appears to be what your current code does (act method first calls getUserInfo, then calls setHigscore, which also taps the server for the UserInfo object). Add a constructor to get the UserInfo object and throughout the rest of the class, just check to make sure it is not still null: If it is null, then you could have it try to access it again (in case server was temporarily unavailable). The loggedIn field is totally unnecessary. (2) You also only need to update the image when the high score is actually changed. Updating the image every act cycle is a waste on CPU time (not nearly as bad as tapping the UserInfo server twice an act cycle, which probably causes some lag on its one if uploaded to the site -- but still wasteful). Call the drawText method from the constructor for its initial image and then again in the setHighscore method during a new high score update. You may want to show the class code where you create and add the Highscore object into the world. It may have something to do with your current issue.