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

1 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Thank you for your advice and explanation dop2000

    Sorry for all the questions, but I have more and I didn't want to split it to new threads as it's somehow related to my confusion, some are a bit off-topic but connected to each other.

    I hope that you'll donate your time as your advice is VERY appreciated and valuable to future confused users. THANKS AHEAD! :)

    .

    First of all, the way you described the (non-array) makes much more sense to me.

    But your last note about so many global variables makes me re-think about arrays.

    .

    .

    First question this is a bit Off-Topic came to my mind once again:

    You've mentioned GLOBAL variables for each item, and I may already start with a BIG mistake here.

    For my Player, I didn't use GLOBAL variables, but instance for it's HP or any other future variables that I will add.

    .

    Is this a BAD thing, will this cause me future issues? when the Player moves to the NEXT stage and such will the variables reset because I'm not using Global? (for all the events) or it's fine and I can preserve them somehow.

    .

    I'm wondering about this, BEFORE I'll start add more and more items and "skills" to my PLAYER character.

    I'm thinking about the option for 2-4 Players in the future, that is why I named it Player 1 (as seen on the example GIF). I'm not focus this right now as I want to complete the base conditions for Player 1.

    .

    Without even the "ITEMS" issue, Should I make a dedicated GLOBAL-VARIABLES event so I can organize them and have better access for basic future game stuff such as: menus, options, Player_1, Player_2 etc.. ?

    .

    I made 3 different Items for the Player to have from the "Randomizer" item for now, so I can start make either a simple Array + Probably Array Editor (still not sure about it).

    .

    The Arrays v.s. Variable decision:

    One problem I noticed in the Array / Array Editor which is more visual to me when it comes to organize:

    Unlike Excel / Google Sheets, I cannot just Drag-N-Drop to change order to re-organize my items later on when I will have hundreds of them. True, it make sense because the code is very precise X 1, X 2, X 3 so if I change some strings or values later on... I'll make a mess and it will take so much time to change manually anyway.

    .

    While as you said, too many Global Variables for the items:

    A HUGE list to play with, but each will have it's own group and I can always Re-Organize the order, put in specific groups add comments and so on.

    Of course in both ways I can use the Ctrl+F to find what I need.

    You've made a good point it is my game, but YOUR advice makes much more sense and helps me to run away from future mistakes so I won't need to Re-Code the all thing or just have hard time to play with the database.

    .

    .

    BEFORE I EVEN BEGIN with the Array / Variables for my Items, The last issue I hope you can help me with:

    .

    As you already understand I would like to make different Items, each time my Player will move to the next stage I want him to KEEP the last item he had (that's probably why I should use Global variables?)

    But then came to my mind another PROBLEM I may need to solve early:

    .

    I want to UNLOCK most of the Items I will add to the game, and I want to make sure that whenever the player UNLOCKED (found) a NEW Item it will be available to him in the future, even in a NEW GAME.

    so I'm guessing, I should make a Global Variable Boolean "LOCK / UNLOCK" (correct me if I'm wrong).

    .

    But what if I want to make 3 SAVE SLOTS for the game? now I lost tracking:

    So what happens to the GLOBAL VARIABLES of the unlocked variables that saved on SLOT 1 ?

    .

    .

    Once again, BIG THANKS to any of the questions you can answer or give me advice as long as I'm still on the early stages of the game, this will help a lot to run away from a bad project management.

    * Sorry about my bad English.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Global variables are not always evil, but in this task (where you need them to store information about lots of objects), they are a very bad choice.

    Instance variables is a good choice for this task, they are much more efficient. You can have 100 items and only 10 instance variables to store all items properties. (With global variables you would have to create several hundreds of them and many-many more events)

    .

    If you have multiple of sprites with similar features, you need to combine them into a family. If you have, or planning to have sprites Player1, Player2, Player3, Player4 - add them to FPlayer family and move all instance variables, all behaviors from sprite level to family level. This will save you a lot of time and efforts in the future and you could organize your code better. For example - instead of four almost identical events "On player1 jump - do something..." you can create just one event "On FPLayer jump".

    .

    I recommend doing the same with items - you can make an individual sprite for each item, but you need to combine them all into a family.

    Individual sprites are probably even better for this job. You can keep them all on a separate (unused) layout "ItemsInstances", fill in all the values into their instance variables. And this will become your database of all items and their properties. When you spawn an item in the game, it will be created with all those properties you defined.

    .

    Don't worry about the Save feature, it saves everything - global variables and instance variables.

  • Thank you so much dop2000 this information is VERY helpful! :)

    I will try to re-manage the game and see what should I put in families and what not.

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