Arrays x Dictionary x Multiple Event Sheets

0 favourites
  • 2 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Hello all!

    I am kinda new to Construct 2 (and loving it, btw) and I always try to keep my code (or events, for this particular matter) as clean and tidy as possible. I would like to know what is the best approach option for two particular cases I am facing in my development in terms of performance and efficiency.

    Case 1: The Player variables

    I have this Player object with many attributes (namely Health, Power and Speed). I have to access those attributes from many different layouts because they will be changed by equipping items on menus and will also affect the game itself, during combat. I figured that I can't set those as instances variables for the Player object because they will be changed on layouts where the Player object is not present.

    Then, I can either:

    • set those values as global variables,
    • as a dictionary or,
    • as an X-only array

    (if there are any other ways to setting these up, please let me know).

    And set them "on load finished" or on my first layout.

    Case 2: The slot system

    I am setting up a slot machine system. Once every X seconds, 3 variables will be randomly set and, depending on their combination, give the Player a special power. I have to set up those individual powers manually (789 powers to go! Woohoo!), but I have to store their names, properties, damage and other attributes somewhere.

    I can either:

    • set them as local variables as I create their functionality on a (very huge) event sheet,
    • as an array, and access the array's properties when the slot machine triggers that specific power's index
    • set them as global variables on a separated event sheet, import that into the "Powers" event sheet and access them there.

    These "Powers" would be set on "layout start" when the game level finishes loading (I guess?)

    My question is, for both cases, what would be the most efficient and clean approach?

    Thanks in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think everyone has his own methods.

    For me, globals are last resort.

    Instance variables are very usefull within layout. To identify instances and set/get instance status.

    If I have more instances frome same type to set to something, I use locals. Because you cant pick from same type twice.

    Finally, to have a database over all layouts, there are dictionary and array, but for me they are to inflexible, so I build my own.

    https://www.scirra.com/forum/plugin-behavior-directdata_t147493

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