Arrays OR Variables: YOUR Advice Please? - (not inventory)

1 favourites
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • Hey All,

    As I keep building my very first game and still learning Construct 3, I ran into something I'm wondering how should I handle it.

    Eventually during time, I will add more and more Items to my game.

    For now, the items are not something you pick from a menu, just pick them and use or maybe switch to another during game. I may change it in the future but for now I want to keep it simple for the style of my game.

    Items may be separated to sections, for example:

    • 1-30 = "Common"
    • 31-50 = "Rare"
    • 51-60 = "Legendary"

    And I will probably add more to each of the sections.

    The Question:

    Should I just split them as above to groups of variables?

    or

    Should I use Arrays / Array Editor for such thing?

    Note:

    I never used Arrays, I don't know if it's hard to create, handle or manage in general.

    I did read about it and understand there is some kind of an organized Array Editor but still, I have no experience in this.

    The reason I'm asking this question is because I will probably keep update the game with MORE and MORE items on each version so what will be easier and smarter to use for such goal?

    If anyone can supply a good tutorial or capx example, it will be easier for me to follow visually since I'm not a programmer and still learning.

    Thanks ahead!

  • Definitely NOT variables.

    You can make a list/reference of all possible items and their properties (damage, price etc.) using the Array Editor.

    For storing items that your characters owns, use another array or maybe a Dictionary. With dictionary you can save item code as a key and quantity as value, for example:

    Key="healthPotion01", value="7"

  • Thanks dop2000 Great example! it looks very organized to work with, I hope it's not hard to do since I never used Arrays before.

    So basically I can always use the Arrays Editor to edit and change my items, order, names and properties as I build the game or add more and more items without ruin what I already added to the Arrays list?

    Of course I'll try to play with it for few items first.

    I'm still confused about what is the use of Dictionary or when to use it, so I guess I'll try to focus Arrays first.

  • You can use Array Editor to create a list, yes, but you still need to load it into the array before using it. (request the file with AJAX, then load into the array from JSON)

    I would give you a tutorial, but with recent changes to the website, it's impossible to find anything...

  • You can use Array Editor to create a list, yes, but you still need to load it into the array before using it. (request the file with AJAX, then load into the array from JSON)

    I would give you a tutorial, but with recent changes to the website, it's impossible to find anything...

    Thanks that could be helpful!

    I tried to understand how to setup an Array with the Editor but with all the extra files or project needed to load I got confused, I don't think it will be sad to have a FILE accessible for others to hack.

    Isn't there a safer way to use array?

    Maybe I should do it via lots of variables like in my first example for ease of use, not sure yet.

    or maybe via Dictionary, I'm not sure if it acts like any normal variables but from reading (consider my bad English) I understood they are faster than Arrays, and giving names for each item may help me.

    As you can see my confusion is huge...

    BTW - I also noticed some issues with the new forum, it won't send me notifications via email.

    I tried to "unfolow" and then "follow" once again, but... I still don't get notifications so I need to check out manually from time to time.

    Sorry about my bad English and thanks again! :)

  • I would suggest making the game first, and then worry about hackers :)

    .

    For example, when you are close to releasing the game, you can copy the content of the file (made with Array Editor) and embed it into the code. This way it will be significantly harder for hackers to modify it.

  • True, I should focus on the game itself as you're suggesting, thanks for the advice.

    And now... to create zillions of variables for each of my items! :D

  • And now... to create zillions of variables for each of my items! :D

    Joking aside - things like this is the reason why so many beginners never finish their games. It may take a few hours to read about the features like dictionaries, arrays, families etc., but they will save you weeks and months of work in the future.

    I've seen too many projects with many hundreds and even thousands of repetitive lines of code, that could have been avoided if the author had spent a little time researching and learning..

  • > And now... to create zillions of variables for each of my items! :D

    Joking aside - things like this is the reason why so many beginners never finish their games. It may take a few hours to read about the features like dictionaries, arrays, families etc., but they will save you weeks and months of work in the future.

    I've seen too many projects with many hundreds and even thousands of repetitive lines of code, that could have been avoided if the author had spent a little time researching and learning..

    I appreciate your advice and I can't agree more with you.

    I did read about the Dictionary and the Arrays / Array Editor, can't say that I understand all of it because I'm a visual person (that's why I use Construct instead of actual writing code).

    So I want to start really simple because the best way to learn is to actually see how it works as doing small experiments and then my brain my scream: "Ahhhhh so this is how it works! got it!" hopefully.

    By starting small I want to try 3-5 items to picked up randomly from the array.

    The thing is, I have no idea how to connect my sprites-items (each will have their own variables or powers) to the arrays. I'm already confused with it and that's where making variables instead may sound like lots of lines even if I'll organized them in groups for each item.

    For sake of organization I have a dedicated "ITEMS" event sheet so I will code anything related to the Items in the game there.

    I looked for a good Construct 3 Arrays + Array Editor and didn't find any in English, and while just playing around with it, it doesn't make any sense how do I make the arrays "talk" with my sprites or how I choose from the array to apply an Item (spawn it to my player).

    Sorry for the long thread, I'm just scratching my head trying to understand how to use the arrays / array editor before I'll have to go to the other wrong choice: variable for each item which I totally agree it is a really primitive way to do.

    Also, I understood that Dictionary will create "key" as a word that holds a value, like string variables but I can make many, and it's more organized and can be called much faster than Arrays from what I read on the documents because in array it needs to search, and I'm planning to do a lot of items.

    So maybe I don't even need Arrays? but a different way with Dictionary?

    I'm sooo confused...

    Thanks ahead and sorry about my bad English.

    i.imgur.com/ijHy7xc.gif[/img]

  • I'm feeling extra generous today, so I made this example of an inventory system with arrays and dictionaries. (actually, updated one of my older demo projects).

    Click items to pick them up. Enjoy!

    dropbox.com/s/rplr7qobzsds9qf/InventorySystem.c3p

  • Thanks for sharing dop2000

    I'll have a look, I imagine how scary the code will look to me but I appreciate your help a lot! :)

  • OK, since I'm still learning and everything is new to me, Arrays... Dictionary... and more.

    I'll try to share my progress consider to this Items idea based on my game-engine because I don't use inventory. maybe it is MUCH more simple to accomplish and your advice will be very helpful.

    The concept:

    As shown in the GIF, When the player pickup the question-mark sphere a.k.a. "Randomizer".

    Next is the tricky part (for me)

    • As I keep working on the game I will add MANY MORE ITEMS.

    Just like the original post, I will need to "tag" somehow some items to different rarity:

    Common, Rare, Legendary.

    • Each item will do something else of course.

    In this case (Example GIF) the "Spring Helmet" will make the Player jump Higher.

    What I've done so far is no Arrays, no Variables or anything for the items because I want to make it on the best cleanest way that it will be easier for me to manage, modify, change, replace in the future.

    Questions:

    1 - Should I keep the ITEMS in 1 sprite, each item is different animation with dedicated name?

    or should I separate to 3 sprites: Items_Common, Items_Rare, Items_Legendary for better management?

    2 - Do I even need to use Array? can I use ONLY dictionary?

    I'm asking because the Array doesn't make any sense to me, the concept of X, Y (I don't need the Z depth) but have no idea how to call it and such. (still learning from experimenting).

    From reading about the Arrays and Dictionary, I understood that searching in Arrays is slower compare to the Dictionary or normal Variables, and I will have MANY items (and will keep expanding in the future) so what will be the best?

    3 - What do I do next?

    Once the player pickup the "Randomizer" I want it to choose from either Common, Rare, or Legendary based on what the Player already unlocked in the game (I didn't got to this part yet, that's another problem).

    I hope you understand my goal and can help me out with good advice as I do step-by-step while learning and experimenting.

    Thanks ahead and sorry about my bad English.

    https://i.imgur.com/BpmZoh3.gif[/img]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK, since I'm still learning and everything is new to me, Arrays... Dictionary... and more.

    I'll try to share my progress consider to this Items idea based on my game-engine because I don't use inventory. maybe it is MUCH more simple to accomplish and your advice will be very helpful.

    The concept:

    As shown in the GIF, When the player pickup the question-mark sphere a.k.a. "Randomizer".

    Next is the tricky part (for me)

    • As I keep working on the game I will add MANY MORE ITEMS.

    Just like the original post, I will need to "tag" somehow some items to different rarity:

    Common, Rare, Legendary.

    • Each item will do something else of course.

    In this case (Example GIF) the "Spring Helmet" will make the Player jump Higher.

    What I've done so far is no Arrays, no Variables or anything for the items because I want to make it on the best cleanest way that it will be easier for me to manage, modify, change, replace in the future.

    Questions:

    1 - Should I keep the ITEMS in 1 sprite, each item is different animation with dedicated name?

    or should I separate to 3 sprites: Items_Common, Items_Rare, Items_Legendary for better management?

    2 - Do I even need to use Array? can I use ONLY dictionary?

    I'm asking because the Array doesn't make any sense to me, the concept of X, Y (I don't need the Z depth) but have no idea how to call it and such. (still learning from experimenting).

    From reading about the Arrays and Dictionary, I understood that searching in Arrays is slower compare to the Dictionary or normal Variables, and I will have MANY items (and will keep expanding in the future) so what will be the best?

    3 - How do I make for each Item a different "power" because it will need different group of events.

    Should I add Variables on the "Items_Common" for example? I'm lost where to add variables or not.

    4 - What do I do next?

    Once the player pickup the "Randomizer" I want it to choose from either Common, Rare, or Legendary based on what the Player already unlocked in the game (I didn't got to this part yet, that's another problem).

    I hope you understand my goal and can help me out with good advice as I do step-by-step while learning and experimenting.

    Thanks ahead and sorry about my bad English.

    i.imgur.com/BpmZoh3.gif [/img]

    i.imgur.com/CyQCDOu.gif [/img]

  • After few days, I'm still scratching my head about this.

    Since I'm not using an inventory, but random Items, each item will have different affect on the player, different powerup and such.

    Should I still work with Arrays / Array Editor for all my items and somehow find a way to "call" them when the item is picked?

    I found Arrays very confusing, I understand it supposed to be more organized like a spread sheet but when it comes to what each specific item does, it's not always just damage or price, it could be anything else I may add to the mechanics of the game.

    I will have many items in my game, that's for sure.

    I've created a dedicated Event Sheet just for the Items, but I didn't program them yet.

    I'm thinking about each Item and it's condition in a group, for example:

    • Group: Spring Helmet
    • [all conditions forSpring Helmet here]
    • Group: Rock Helmet
    • [all conditions to Spring Helmet here]

    And I will add more Group (items) to this event sheet...

    But that's where I get confused, how do I combine this with the Array / Array Editor?

    How do I "call" these items USING the array system?

    It may sound very complicated to me and very simple or obvious to you, but that's because Arrays are new to me, not in the idea of what it does (I understood that), More in how to use it and WHEN should I use it in Construct, since I understood from the docs it is SLOWER to search compare to variables.

    I hope that you understand my confusion, I'm learning and that is why I'm asking for your advice,

    most of you have much more experience than I do and I appreciate any help.

    So, should I go for a different approach here? any Advice please?

    Thanks ahead,

    No inventory, random items:

    (Should I use Arrays for all the items?)

    i.imgur.com/QIU3chJ.gif [/img]

    i.imgur.com/M5iAnOq.gif [/img]

  • So many questions..

    If you have lots of different items with lots of properties and you want to generate one at random, you need an organized way to store all this information. Lets call it the database. In C3 probably the easiest way to do this is with arrays (because of the Array Editor).

    My example project has this database, you can add more items to it and more properties, just need to create functions to retrieve them. You can have multiple arrays (say, one for weapons, another for consumables).

    .

    .

    Here is how you can do this without any database:

    If you were placing all these items manually onto the layout (for the character to find), you can store all information directly in sprites.

    Create a few sprites - Weapons, Potions, Food, Tools (or Basic, Legendary, Rare, whatever) with multiple animations.

    Add them all to ITEMS family, and define a bunch of instance variables on the family, for all possible items properties - "damage", "run_speed", "jump_strength", "price" etc..

    So when you place these sprites on layout, you will need to manually set an animation and enter values into these instance variables.

    E.g.: animation="small_sword", damage=10. Leave unused variables empty.

    .

    So how do you give a random item to the player?

    You can put all these items off-screen, all hundreds or them.

    When player picks up a Randomizer, select a random instance of ITEMS family and move it to player's position.

    .

    It's your game, so you should decide how are you going to do this.

    One thing I know for sure is that making hundreds of global variables to store all this data is definitely a bad idea.

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