Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How to get thelas value form a hash?

That 's realy it, How can I get the last value from a hash?
$hash = {}
for i in $game_map.events.values
$hash = i.x

How Can I get the last value from that HASH?
 
I was wrong, btw. Interestingly enough this game up in a script i'm making right now and I realized its this:

last_value = $hash.values["#{$hash.keys.last}"]

the .values is what I was missing before.
 
last_value = $hash.values["#{$hash.keys.last}".to_i]

I again editted it to get it to work x_x

I'm not sure if -1 index works for aHash object. Simply because there is no mention of it in the documentation whereas there is a mention of it in the Array class documentation. But I could easily be wrong.
 
Ok so this means that.
Code:
$hash = {}
for i in $game_map.events.values
  $hash[i] = i
end
and the last event in the map is event03

So to get the last Id I would use..
$hash.values[-1]
and it would return 3?
 
yeah it should return event 3

you can test it if you know that it's event #3 :

Code:
$hash = {}
for i in $game_map.events.values
  $hash[i] = i
end

p hash.values[-1] == $game_map.events[3] # should return true or false
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top