Hi, I've been using Construct for a while, but this is my first time posting on the forums. I guess you'll be seeing more of me in the future as I'll surely get stuck again at some point, but I hope to eventually get good enough to help others.
<font size="5">Ok, this is the situation:</font>
I've been working on a game, I have a character (the player) always carrying a melee weapon (separate sprites) pointing upwards (0 degrees).
When pressing "c" on the keyboard the weapon is tilted back -30 degrees and then it rotates 210 degrees (180 + the 30 it tilted in the begin).
If the c key is hold for a certain amount of time and then released, the weapon will rotate 390 degrees (360 + the 30 it tilted in the begin)and will be a little faster. Something similar to the "spin attack" in Zelda games.
The longer you hold c the stronger the attack will be, there are 3 levels of charge (these levels are not relevant for the current problem).
<font size="5">To do all this, the player's sprite has 2 variables:</font>
1) charge_lvl:It goes from 0 to 3, the default value is 0 representing a regular 210 degrees attack, from 1 to 3 is a charged 390 degree attack. For the issue at hand there is no difference between 1 to 3 values, it only matters if it is 0 or greater than 0.
2) lock: It goes from 0 to 1. Default is 0. When the attack "animation" starts I set it to 1, when it ends I set it back to 0. An attack can be performed only when the value is 0, this is to prevent the player to interrupt the attack's animation by pressing c repeatedly.
I do the attack's "animation" by rotating the weapon 30 degrees, waiting a fraction of a second(0.03 or 0.02), rotating another 30 degrees and so on until the 210 or 390 degrees are completed. At the end of each attack there is a little extra waiting time (0.5 seconds).
<font size="5">There are 3 events:</font>
1) c is pressed: This tilts the weapon -30 degrees.
2) c is down: every X seconds the value of charge_lvl is increased.
2) c is released: this is divided in 2 sub events: When charge_lvl is 0 and when it is greater than 0. In both cases the attack's "animation" is activated, the only difference is that when charge_lvl is greater than 0 it has additional rotation steps in order to complete the total 390 degree rotation, also, each step in the "animation" is faster (the waits are shorter).
Ok, that is the way I'm working, now, the actual problem:
Sometimes when pressing c without holding it does the charged attack(390 degrees) instead of the regular attack (210 degrees). This happens occasionally, try it a few times to see.
I don't really know where is my error, but I have the feeling it has something to do with the "wait X seconds" condition.
In my actual game there are enemies, sound effects, visual effects etc, to make sure none of these things had anything to do with my problem I recreated the basics elements associated with the problem into another very basic project. The results were the same so I guess there is a problem with my logic or my understanding of some event.
(Also, I've tried with Firefox, Chrome and IE, same results)
So, I'm asking for help to find out a solution to the problem.
The .capx can be downloaded here:
And these are some images of the project.
<img src="http://imageshack.us/a/img201/82/o1ed.jpg" border="0" />
<img src="http://imageshack.us/a/img24/2273/ipjb.jpg" border="0" />
<img src="http://imageshack.us/a/img833/2126/5lkx.jpg" border="0" />
* The number on screen is the current value of the charge_lvl variable I added it for debugging purposes.
* The wait every X seconds sentence is set to high value (9 seconds) in order to make sure that said amount of time is NOT passing end therefore it shouldn't be activating the charged attack.
Thanks in advance ^_^