Arrays x Dictionary x Multiple Event Sheets

Get help using Construct 2

Post » Thu Jun 25, 2015 11:42 am

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! :)
Posts: 1
Reputation: 177

Post » Thu Jun 25, 2015 12:30 pm

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.
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
Posts: 158
Reputation: 1,303

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests