How do I make an inventory? I'm learning to use arrays

0 favourites
  • 3 posts
From the Asset Store
Inventory Aid
$4.90 USD
Create grid-based game inventories and items easily.
  • Don't mind me if I do, but I'm using c2 free version. So I have to insert the values to the array manually.

    at the moment, I'm trying to make an inventory with text objects. I wish to make them show as:

    - Salt 0 10$ 1kg"

    I setted the array values like this:

    -At layout start

    - set value at (0,0) to Salt //name of the item 1

    - set value at (0,1) to 0 // quantity

    - set value at (0,2) to 10 // price

    - set value at (0,3) to 1 // weight

    - set value at (0,0) to Food //name of the item 2

    - set value at (0,1) to 0 // quantity

    - set value at (0,2) to 5 // price

    - set value at (0,3) to 5 // weight

    And so on...

    to set the text object I used the "array.at" like this:

    set text to: "-" &array.At(0, 0)& " " & array.At(0, 1) &newline& array.At(0, 2) & "$ " & array.At(0, 3) & "kg"

    And I did this with both items (I wish to create more)

    It worked, but it seems that this is very inefficient method to set text. Does anyone know an expression, or a way that I can organize the array to make it better?

    I tried to use expressions like array.curX or curY or Loop index. But to be honest, I don't really understand them enough to make them work. But somehow I THINK that is the solution.

    Tagged:

  • - set value at (0,0) to Food //name of the item 2

    Did you mean set value at (1,0) ?

    To list all items from the array you can do this:

    Repeat array.width times
     Append text: "-" &array.At(loopindex, 0)& " " & array.At(loopindex, 1) & " " & array.At(loopindex, 2) & "$ " & array.At(loopindex, 3) & "kg" & newline
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah, I mistyped... I will test it out, thanks!

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