Hello all!
I'm trying to condense my code and make it as clean as possible.
I currently have three different objects that display recoil/shaking when shot by the player's bullets. Instead of having three events each with the same set of actions (but each changed to 1 of the 3 objects), there must be a way of condensing it (into a function?). I did try putting the 3 objects into a family and having the function affect the family, but it turns out this affects every member of that family. Here's a more concrete example with sine behavior providing recoil (could be done with shake or other behaviors):
When sPlayerBullet collides with sTree:
--destroy sPlayerBullet
--Store sTree's X and Y positions in instance variables
--set sTree sine cycle position to 0
--set sTree sine inactive
--set sTree sine active
--set sTree sine magnitude to 3
--set sTree sine period to 0.2
--set sTree sine movement to horizontal
--wait X seconds
--Set sTree sine inactive
--Restore sTree to the stored X and Y positions
The same event is copy/pasted for sFlower and sBush, (but with the correct object) so it's the same set of code 3 times in a row. Is there a way that I can have this set of actions only once in the event sheet for efficiency? Even using function parameters, it seems that I would still have to copy paste the code 3 times, and a simple "or" condition would still have to specify which objects to act on. But ideally, it would look like this:
When sPlayerBullet collides with (sTree, sBush, or sFlower)
--Call function "Recoil"
and then:
On function "recoil"
--destroy sPlayerBullet
--Store tree, bush or flower x and y positions in instances variables
--(same as above example)
--restore tree, bush or flower to x and y positions
Thank you!