How do I get items from an array?

0 favourites
  • 4 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Evening folks!

    This might be the biggest newbie question ever, but how do I get an array to return a number on the same line as an item's name?

    Lemme explain...

    So I'm building a game about collecting different types of fish, and I figured the best way to start would be just to make sure I can get the core basics for the game first.

    I get my "test" build done, just a button that tells me what fish I got, and some text that tracks how many I caught. Good! That's exactly what we're looking for, so why am I asking a question? Well...

    This is horribly inefficient. If I wanted to add more fish to the list, It would just be repeating a ton of code just to track the fish, and while I'm not sure if it would, I feel like it might lag out the game a little to have this much repetition.

    I tried to add an instance variable it would look for, or try to just use the text from the array itself to update a number, but it just wouldn't work because they're 0-based. Here's where I stopped before getting too upset over the lack of progress:

    Is there any way I can make the array iterate based on the fish I caught, and then add a number to the (2,Y) segments? (1,Y) is where I'm storing fish ID numbers for now.

  • Evening folks!

    This might be the biggest newbie question ever, but how do I get an array to return a number on the same line as an item's name?

    Lemme explain...

    So I'm building a game about collecting different types of fish, and I figured the best way to start would be just to make sure I can get the core basics for the game first.

    I get my "test" build done, just a button that tells me what fish I got, and some text that tracks how many I caught. Good! That's exactly what we're looking for, so why am I asking a question? Well...

    This is horribly inefficient. If I wanted to add more fish to the list, It would just be repeating a ton of code just to track the fish, and while I'm not sure if it would, I feel like it might lag out the game a little to have this much repetition.

    I tried to add an instance variable it would look for, or try to just use the text from the array itself to update a number, but it just wouldn't work because they're 0-based. Here's where I stopped before getting too upset over the lack of progress:

    Is there any way I can make the array iterate based on the fish I caught, and then add a number to the (2,Y) segments? (1,Y) is where I'm storing fish ID numbers for now.

    Whoops! Forgot to add the little array I set up to make it easier to explain. Here it is:

  • If I'm understanding correctly you can use an array 'for loop' to run through X,Y where X=1 and Y = loopindex while you look for the fish name, if curY = "fish" then stop loop and add 1 to x=2,y=loopindex.

    Note : I find it easier to do it where X row is the new fish and Y columns are the values, although it looks backwards in the array file I find it just makes more sense in events but that's up to you...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the quick reply! I'll give this a try as soon as I can.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)