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 delete a hash key...

you selected in a selectable window? I mean, I created a menu that would list all the hash keys and doesn't show their values.

It wasn't necessary to show the values, I just wanted to let the player delete a hash key without typing a specific id number, an id that should be equal to the hash key he wants to delete. So let's say the player selects the third key like in this example:
______
| ID 1 |
| ID 2 |
| ID 3 | <<
| ID 4 |
______

In this case the 3rd key should be deleted. I know about the delete method: some_hash.delete(3), but the player is not supposed to type any number so the program should look for one on its own.

How should I delete a single key then?
 

poccil

Sponsor

I find your request different to follow.  If you're trying to search through a hash for a certain ID according to the index (position) in the hash, then you should know that hashes are unpredictable in how they order keys within the hash, so a search by index is not always reliable. 

Also, a hash is appropriate only if the keys in the hash can be strings as well as numbers.  Otherwise, an array is more appropriate.
 

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