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.

Grabbing a SELECTED Item's ID

jayje

Member

I'm working on a custom crafting system for my game and was wondering if there was a way of adding a selected item's ID to a variable. Meaning if I choose an item, it's ID gets added to a variable to use later. Any thoughts or feedback are welcome.
 
Solution
I don't know the exact syntax and class names off the top of my head. But your itemlist is an array, and the cursor index tells you what position you are in. The thing to remember with index positions is that the first element is 0. Second item is 1 and so forth...

array = [item1, item2, item3]
cursorIndex = 0
array[cursorIndex] #=> item1

So you want to do something like...
newVar = array[cursorIndex].id #=> newVar = item1.id
I don't know the exact syntax and class names off the top of my head. But your itemlist is an array, and the cursor index tells you what position you are in. The thing to remember with index positions is that the first element is 0. Second item is 1 and so forth...

array = [item1, item2, item3]
cursorIndex = 0
array[cursorIndex] #=> item1

So you want to do something like...
newVar = array[cursorIndex].id #=> newVar = item1.id
 
Solution

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