[Solved]Setting effect parameter affects all instances

Just started using Construct 2? Post your questions here

Post » Sun May 21, 2017 9:11 am

Hi, I create a square (with bullet behavior) every 1 second with some random values for it's size, speed, spawn coordinates.
For these values, it's working correctly, each instance has different values and they do not change during their lives.
But I also have a ReplaceColor effect that is changed randomly between 3 colors on creation of the square.
This one affects all square instances, not only the newly created one.
Image
(Click on image to go to it's full size)

I have a Construct license for some times now but I never used it so I'm a newbie and don't see where I did something wrong.
Can you explain how can I change the color of the newly created square without affecting already created squares?
Thank you.
Last edited by NitroBanco on Mon May 22, 2017 7:50 am, edited 1 time in total.
B
4
Posts: 5
Reputation: 210

Post » Sun May 21, 2017 11:08 am

When you recreate a new instance of an object, construct 2 uses its default values to Initialize the instance. You can have the function called after the new object is created to change its stats, or keep the first instance of the object somewhere in the layout, and change it values on layout load.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Sun May 21, 2017 1:34 pm

Thank you for your answer, sorry but I do not understand what I have to do, I'm not sure it answers my problem.
This is what my function does:

Image

Everything works great, each instance has it's own size, speed, and spawn coords.
But the ReplaceColor affects all instance, I do not want that.
I'd like that each instance keeps the color that was defined at creation. The same way it keeps its size and speed.
So why does it work for size and speed but not for color?
B
4
Posts: 5
Reputation: 210

Post » Sun May 21, 2017 2:17 pm

Okay I see what are you trying to do, when you change the color it changes for every single instance, but you want it change for 1 only. This can be little tricky to implement. Add a global variable called color_picker, add the same variable as a instance variable to the square object. When you create your object increment both the local and the global variable by 1. Add the change color function, and call it with a parameter which is equal to the instance variable. This means that the function will trigger only once on the object with the current id, the next will spawn with different id because we are increment it by 1 each time you create the object and it wont be effect by the function.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Sun May 21, 2017 8:42 pm

I tried but I must be dumb, it's still behaving the same.
If you ever have time to test it and make a working example that would be awesome but even if you can't I thank you for your time and answers.
B
4
Posts: 5
Reputation: 210

Post » Mon May 22, 2017 12:20 am

Here is an simple example I made, the event is bit different then my explanation above, but it does the trick every instance is created with a different random color.

https://www.dropbox.com/s/etc3o79zi004t ... .capx?dl=0
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,367

Post » Mon May 22, 2017 7:10 am

Ok, I'm sorry it's my fault.
It was working from the beginning... on Construct 2.
I didn't realize I'm on the C2 side of the forum but I'm actually working on C3.
It works on C2 but not on C3, even your example code. So I guess I found a bug.
I will go signal it on the C3 side of the forum if it was not already.
Thank you.
B
4
Posts: 5
Reputation: 210

Post » Thu Jul 27, 2017 2:13 am

I am also working in C3 and had issues with setColor. For example the capx above wont work in C3 unless you just use one setColor action.

Set effect "SetColor" parameter 0 to rgb(255, 0, 0)

In this case, that is bright red.
B
14
S
2
Posts: 67
Reputation: 2,044

Post » Thu Jul 27, 2017 8:16 am

In C3 it's normal to use only one parameter like this : rgb(red, green, blue)
instead of 3, one for each color, as it was on C2.
So what you are describing seems normal.

As for my specific issue, I reported it on Github there : https://github.com/Scirra/Construct-3-bugs/issues/311
And it was fixed in r32 update.

Edit: Just to be sure, parameter 0 is source color, parameter 1 is the color you want; so if you want red it should be:
Set effect "SetColor" parameter 1 to rgb(255, 0, 0)
B
4
Posts: 5
Reputation: 210


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests