How do I make stack sizes in an array

  • I need help with stack sizes in an array. When I add an item- lets say 5 blueberries, when the max stack of it is 10- can I make it loop so it add 1 blueberry 5 times so it get every individual stack before creating a new one?

  • Yes. Make a variable called loopCounter (or whatever) and set up logic like this.

    Set loopCounter = number of berries to be added to stack (in this case 5)

    Set up a While loop:

    While loopCounter > 0:

    • sub event: if berry stack in inventory = 10, create a new stack of 1, -1 from loopCounter.
    • sub event: if berry stack in inventory is < 10, +1 to stack, -1 from loopCounter.

    The script should loop through until it runs out of berries to try to add to the stack. But do note that this is off the top of my head and hasn't been tested.

  • Okay I will try this thank you I will grt back to you with the results. Cheers!

  • also what if there are other values inbetween a blueberry stack. for example a raspberry, how do i make the computer essentially skip that value and move on until it hits the end of the array or another blueberry stack?

  • What's the problem?

    Your array could look like this:

    strawberry, 10

    blueberry, 7

    raspberry, 10

    raspberry, 4

    strawberry, 1

  • okay in your array, lets say I want to add 8 raspberries. How do I make it add 6 to the last stack then push another stack?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • mikehive explained you how in his comment!

    Use a loop, when the stack reaches maximum size, create a new record in the array (for example you can use Array-Push action).

  • what if I want to add 18 raspeberries? you add 6 to the 4 stack, create a new stack with 10. that leaves 2 left. How do I add a stack of 2 afterwards on a loop?

  • It doesn't matter, you can add multiple stacks in one loop..

    For example:
    quantity=18
    stackIndex=5  (index of "raspberries" stack in the array)
    
    While quantity > 0
        if array.At(stackIndex,1) = 10 
                 // create new stack
                 Array Push "Strawberries"
                 stackIndex=Array.Width-1
     
        // add 1 to current stack, subtract 1 from quantity
        Array set at X=stackIndex, Y=1, value=(array.At(stackIndex,1)+1)
        Subtract 1 from quantity
    [/code:2jbzvvpw]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)