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

Report as inappropriate.

shrucis1
shrucis1 presents ...

2013/12/29

Reusable UserInfo Support Classes

It's nothing fancy, and I haven't added any documentation yet, but they're some classes that support storing 1-byte values using the string at index 0.

The classes for this are UserState and OtherUserState.

All the other classes are used as a demonstration.

How the demonstration works: You clicked on the colored buttons to change their color. Click the store button to store those colors under your username. To see the colors someone stored, press the get button and type in their username. It doesn't support letting you look at everyone whose used the scenario, but if someone hasn't used it and you get their colors, it will tell you that the user cannot be found.


How the storing code works:
The idea behind using the strings instead of the 10 integers is that if you're already using the integers for something else, so long as you have one free String, you can store up to 50 different 1-byte value. A 1-byte value is like an integer, but must be between -128 and 127. I may plan on expanding this and adding documentation, but as it is, it's probably only going to be used in one of my upcoming projects.

If you're interested in using the classes, you can download the source and look how I do it and you can ask questions below.

NOTE:
Sorry, but you must be logged in to use this scenario.

3383 views / 9 in the last 7 days

1 vote | 0 in the last 7 days

Tags: demo with-source userinfo

open in greenfoot
Your browser is ignoring the <APPLET> tag.
HTML5 version not available | Scenario not running?
bournebourne

2013/12/30

Every char is 16 bits. And right, but I wouldn't of cast to a byte. I was thinking maybe the storage server some reason had only allowed for byte size space for each character, when storing the strings. But not that way anymore I guess
bournebourne

2013/12/30

All values in range [55296, 57343] were mapped to 63 (after storing and retrieving through UserInfo) - which is the character: '?'
A new version of this scenario was uploaded on Mon Dec 30 02:54:03 UTC 2013 Expanded limit to 50000, not yet sure if all numbers in this range work or not. Remapped the value of 13 to 50001, so setting a value to 13 would no longer fail.
shrucis1shrucis1

2013/12/30

Fixed the 13 bug, and the limit is now 50,000 instead of 128. Just a tiny improvement. XD. Solved it by mapping 13 to 50,001. Going to fix the 92 bug too by mapping 92 to 50,002
shrucis1shrucis1

2013/12/30

If any further bugs arise, I'm pretty sure I have more than enough values to remap to.
bournebourne

2013/12/30

You should remap value 92 as well. Also, I just noticed the scenario doesn't seem to actually save my colors when reloading it. Like loading your colors gives me all red.
shrucis1shrucis1

2013/12/30

That's odd... I loaded my own colors and got all red...
shrucis1shrucis1

2013/12/30

OH! I just realized the bug, bourne, when you reload the scenario, to avoid loading a user that didn't set values, as soon as you start the scenario with all red I store the red values. This isn't a problem with the classes I'm provided, it's a bug in the world class I use, I'll try and fix it later, but I think I'm going to retire for the night, I'll probably work on it in the morning.
bournebourne

2013/12/30

Sounds good
A new version of this scenario was uploaded on Mon Dec 30 03:16:10 UTC 2013 Remapped the value of 92, fixed a bug where your colors were overwritten every time you refreshed the scenario.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

bourne