Instance variables Vs Arrays

From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hello colleague,

    For a long time I was undecided about the best method of organizing game data. I tried 2 methods:

    1. Data storage and processing within sprite instance variables

    2. Data storage and processing within Arrays, with Sprite UIDs for calling sprites

    Seems to me first method is easier and faster to work, due to visual recognition and calling variables, while second method is easier for storage saving (AsJSON), as well as for data comparing, but visual recognition is harder (the form of the array and content should be written down somewhere).

    For example, I have game level map layout, whith level numbers as well as level completion progress.

    Shall I:

    1. create everything on level map layout and give instance variables to all levels (LevelNumber, LevelCompletion, etc.), with writing neccessary data to Array for saving game to local and cloud storage, as well as with data export from Arrays into sprite instance variables on start on layout; or

    2. create map background only, with multiple image points for creating levels positions on every layout start, based on Array editor and AJAX importing, while sprites would have only ArrayColumn instance, for array orientation.

    What are your experiences in that area? Which method is better for game organizing for you, or there are some other ways?

  • "For example, I have game level map layout, whith level numbers as well as level completion progress."

    This can be stored as global variables or in an array. If you need any other advice you should give more details about the game and what data you are storing.

  • "For example, I have game level map layout, whith level numbers as well as level completion progress."

    This can be stored as global variables or in an array. If you need any other advice you should give more details about the game and what data you are storing.

    Hi , thank you for your reply.

    The map is scrollable up-down, with about 200 levels connected with roads between them. In principle, the most variables are levels and map resources (coins and energy), while other things are just aesthetic images.

    There are various types of levels and every type have its own sprite. Every level have max 3 stars and every star is shown in accordance with player progress.

    If we go with global variables for every level, would that mean a minimum of 200 global variables is needed for all levels? Isn’t that a lot of global variables just for that purpose, or is that fine?

    So far I have tried 2 ways, one with level instance variables, because each level have more instance variables like LevelType, LevelNumber, LevelCompletion, etc., while second way is with arrays.

    In first way I created all levels on layout together with instance variables. Then I put all levels into Family and and on start of layout all levels are chacked with For each level, etc.

    While in second way I tried with Image points on Map background image and connected them with Array editor via AJAX and every layout start levels are creating based on array data and Image point positions. Then I save this array on Local storage.

    Both ways give me the same result, but first way is faster and clearer for code, and second way is slower, with full of array commands insted sprite.variable, but easier for game saving and later comparation between levels.

    I'm still trying to decide which way to go. Personally I prefer to work with arrays and dictionaries, but I also like and sprite instances.

    What do you think, what should I do?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Now I know what data you are storing it should be an array, you can link the levels to the array rows by instance variable.

  • Now I know what data you are storing it should be an array, you can link the levels to the array rows by instance variable.

    And I like that way the most -> create levels with instance variables on map and import them into array for further processing and data storing. Thank you very much for your opnion.

    But one thing bothers me. After initial importing instance variables into array these variables become unusable if I do not process them back, together with Array, because all further processing takes place within the array, with sprite calls, and and instances would only serve if there is nothing in LocalStorage, as the initial starting points.

    Is that fine, or does that mean that after each array update I have to update and sprite instance variables, so as not to confuse later during the game debug with different data. What do you think?

  • I imagine the process to be like this :

    End of level, update stars value in the array for that level

    On map screen load, update all level images based on array data

    Another way to do it is to just use variables and use 'save' game to save the state of the game. You wouldn't need a global variable for each level, probably one track to track the current level and the stars obtained then when you return to the map you update the relevant level. Problem with this is that it is not permanently stored anywhere and it's hard to track if bugs occur, but you can give the level objects 'persist' behaviour so their variables remain the same.

  • I imagine the process to be like this :

    End of level, update stars value in the array for that level

    On map screen load, update all level images based on array data

    And I like this way the most. I think this is the way I will go. Thanks a lot to solve the dilemma.

    Another way to do it is to just use variables and use 'save' game to save the state of the game. You wouldn't need a global variable for each level, probably one track to track the current level and the stars obtained then when you return to the map you update the relevant level. Problem with this is that it is not permanently stored anywhere and it's hard to track if bugs occur, but you can give the level objects 'persist' behaviour so their variables remain the same.

    I wasn’t thinking about persist behavior because I made code which is imported all data back from savegame array into sprite instances, on layout start, and updated the instances after each matrix change, purely to keep debug up to date. I will try and persist behavour, but now I am most for the first way you said.

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