Hi guys,
I'm trying to make function with several parameters to optimize my code created with Construct2 interface, but I don't understand how it works properly...
For example, I've 10 different sprites objects which have the same behaviour with different settings like :
each time one of this 10 objects is clicked, this object is alpha 10, 30 or 50%.
if this object is 10% or 30% alpha, play animation A, else, play animation B.
On my point of view, I can obviously copy and paste with the interface the same code for each object like :
object1--> is clicked --> alpha 10% or alpha 30% & play animationB1 --> else --> play animationA1
object2 --> is clicked --> alpha 10% or alpha 30% & play animationB2 --> else --> play animationA2
object3--> is clicked --> alpha 50% play animationA3...
but that isn't optimized.
So, I would like to create a function with the interface like :
function detectAction(objectSelected, animationSelected, normalAnimation) {
with this [this is the objectSelected parameter of the function and can be set dynamically, for example with a object list coming from a table]
if this --> alpha == 10 or alpha==30
play AnimationSelected
else
play normalAnimation
}
so I would like the function execute the code for an equivalent of "this" where this is dynamical.
Like that, I can reuse the function in several case, in for loop...
but I don't understand how to call an object name dynamically and I don't see any "this" equivalent.
Could you help me ?
Many thanks,
Rosedestemps