using variables and timers to control combos in a platformer

Just started using Construct 2? Post your questions here

Post » Mon May 26, 2014 5:10 pm

hey all, I'm not technically a beginner but I'm still a novice when it comes to construct. I have a platformer that uses timers to control the input from the user during an attack animation. the "attack" timer is set 0.5 seconds and the structure looks like this

attackwithtimerOne.jpg


i have global variables controlling the attacks but my question is would it be better to control the player with instance variables since these moves only apply to him. I plan on adding about 5-6 more combos, so would it be better to create a global variable, say called combo power up, to control the characters abilities as they are learned throughout the game. like: if global variable "attackpowerup" = 2 then add the 4th attack in the combo. just curious and any help would be much appreciated.
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 38
Reputation: 626

Post » Tue May 27, 2014 2:41 pm

@ashburp

In my experience, it is always better to have variables local to the object using them and only use globals where there is no object which could logically contain them. Global variables always have the possibility of causing odd bugs. Plus these kinds of bugs can be extremely hard to debug. Even when using a variable that is manipulate by multiple types of objects (for example, health on both the player and enemies), I create a family and add the variable to the family. That way it still keeps the variable local to the group of objects using it.

Not only does this protect against bugs but, when your project gets really large, you always know where to look to find the variable. If you have some instance variables and some global variables, it takes more effort to keep track of where to find them and what they do.
B
39
S
12
G
11
Posts: 331
Reputation: 7,727

Post » Tue May 27, 2014 6:06 pm

okay, I plan on making a pretty decent sized game. I've just been making the characters move list and regular functions now (128 events). things are starting to get a little unorganized. I think I'll redo everything as instance variables since they only pertain to the one character and use a global variable to control the progress of the character in the game. Thanks for the help FragFather and for reminding me about families.
B
8
S
2
Posts: 38
Reputation: 626


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests