Object ID's and related objects

is there any way to retrieve object X from a collection of objects through the correct object_id?


whatever the object, the object_id is always unique, right?


can I bring up whatever object corresponds to a specific object_id which I got from the very same object itself?


I made a hash unique by filling it up with object_ids as its keys..... now I want to print out the name of the actors instead of the ids.


can I change the keys on the fly?


this:


hash.each_pair{|k, v| k = $game_party.members.find {|a| a.object_id == k}.name}


still prints out the hash as initially filled: {object_id => result}


I know I can use the battler as the key, but if I print it out for debugging, it prints out the object battler, which takes a lot to debug!


and I can't use the battler's name as a key because there could be duplicate names that would mess up the rest of the code, hence why I went with object_ids
It's been a while since I worked with Ruby, but I don't think you can change the hash like that. From what it looks like, you're trying to run through each hash and dynamically change they key that it gives you as part of each_pair. I'm willing to bet that if you were to print out "k" after you reassign it, it would be the actor's name, but that the change isn't propagated (stored) back to the hash itself. It's likely that the k and v values are just copies of what they are in the actual hash. If that's the case you could build a new hash using those values (I think, I kinda forget the coping to each_pair), but aside from that I don't think you can change the hash this way. Usually when a function in ruby alters the object it's called from, the function name ends in an exclamation point (!).
I'm willing to bet that if you were to print out "k" after you reassign it, it would be the actor's name, but that the change isn't propagated (stored) back to the hash itself.

yes.


that's what's bugging me off.


I could make it in two steps, and make a new hash..... maybe....


I just wanted to know, from Ruby users, if there is a sort of global collection of objects that I can access.
What do you mean global collection of objects? Every object in Ruby's memory? Or every object of a type? I'm not sure what you're looking for.
What do you mean global collection of objects? Every object in Ruby's memory? Or every object of a type? I'm not sure what you're looking for.

yes, every object in memory.


that's kind of the point of having an ID system, to identify multiple instances of the same class.


I just patched it with a second hash..... for the purposes of readouts, it'll do.

Original thread: https://forums.rpgmakerweb.com/threads/object-ids-and-related-objects.71129/