ID:151961
Aug 5 2008, 3:42 pm
|
|
In my game, in order to avoid having thousands of lists that aren't being used at the moment, will write attack lists for each pokemon to a save file. I plan on doing this by writing a unique index in a player's save and saving the list there. I plan on allowing players to skip giving each pokemon a name and having the generic name take it's place (ex: Pikachu) like in the games. If a player has 10 pokemon named "Pikachu" problems can arise, and thus I plan on giving each pokemon an individual ID. The question is, though, how would I go about doing this?
|
In response to Kaioken
|
|
Adding might be a good way to handle it, considering that each player will probably never catch enough pokemon for the var to turn into 1.#INF. Unless they have h4x.
Kinda stupid on my part for not thinking of that, thanks! |
In response to Jeff8500
|
|
Well, BYOND does have a limit on number precision, but that starts at around 16 million, so I don't think you'd have to worry about it here. ;) You could even change the above example to initialize the id number to 100,000 or something, if you want it to be more like the Pokemon games, since it's not kewl to have your Pokemon's ID like, 4. =P
|
In response to Kaioken
|
|
Hexidecimal or Octal works fine for coolness.
George Gough |
In response to Kaioken
|
|
It's not a trainer ID exactly, just a unique number to tell it what list to load. But yeah, 4 isn't cool. In fact, all powers of 2 below 130670 are uncool.
|
In response to Jeff8500
|
|
Jeff8500 wrote:
It's not a trainer ID exactly, just a unique number to tell it what list to load. But yeah, 4 isn't cool. In fact, all powers of 2 below 130670 are uncool. Hate to be semantic when you're making a joke, but that's not a power of 2. The closest power of 2 (131,072) is 2^17. =) |
In response to Kaioken
|
|
Yep, IEEE single-precision floating point is accurate to 16,777,215 (as there are 24 bits in the significand of the 32-bit variable and 8 bits in the exponent).
|
In response to Kaioken
|
|
A more readable way would be to put it in the datum itself:
Pokemon |
In response to Android Data
|
|
Doesn't matter one bit. The little 'readability' you gain is offset by the need to read an extra word and indentation. =P
And if you use the reverse ++ version, you don't need to be tricky and set the var to your wanted amount-1. Simpler, more... readable, right. :D |
In response to Jtgibson
|
|
I usually don't try mental math outside of the hundreds, so give me some credit :P
|
You can have it so everytime a mob/Pokemon is made(with New()) Have it make a random id like: 1f2G345 Then check if that id is in a list of id's that you've made, if not then add it. With this you would have millions of possibilities and have the id's still look cool and all be similar. Then just make sure the list gets saved everytime something is added, or if the server gets rebooted or shutdown.
|
In response to Bakasensei
|
|
Of course, but that's just inefficient. The list would just get huge with time, and it will loop through it every time a Pokemon is created.
|
In response to Kaioken
|
|
Kaioken wrote:
Doesn't matter one bit. The little 'readability' you gain is offset by the need to read an extra word and indentation. =P It's not just easier on the eyes if the variable is defined in that scope, but the variable "last_pokemon_id" is no longer defined globally, meaning you can use that name for other things if need be. Since the ID will only ever be used by a /Pokemon object, it's best to define it in that scope only to keep your project maintainable. And if you use the reverse ++ version, you don't need to be tricky and set the var to your wanted amount-1. Simpler, more... readable, right. :D I prefer ++id because it makes more sense to my android brain. :( |
That's kind of simple if you go about it like this: