Best way of interacting with different instances?

Get help using Construct 2

Post » Wed Dec 28, 2011 3:11 am

I see, you might like my bit plugin I should release it
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Dec 28, 2011 3:18 am

You don't need to do that for each star.
Basically, when you have some repetitive task to do in programming, you have to tell yourself that there HAVE to be a way to avoid copy/pasting.
Because after all... Good programmers are lazy programmers :D

The way to avoid that is loops

basically do a foreach on your stars and look at the corresponding value in the Array

[code]System: On start of layout
System: foreach Star
Array: Value at(Star.ID) = 1
   -> Star: Set opacity to 20
FirefoxIcon(wtf?): On collision with Star
   -> Star: Set opacity to 20
   -> Array: Set value at(Star.ID) to 1[/code]


And why do you need two dimensionnal Array? Value at (X,Y) you only need a Value at(X). If its value = 0 your star isn't picked, if it's 1 it is.Yann2011-12-28 03:20:16
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Dec 28, 2011 10:03 am

That does work wonders indeed, thanks, it's a good trick to use the Star.ID to automatically select the position in the array.
I wanted to use the Y axis to separate each game level in the array, 0 would be the first level, 1 would be the second level...you're suggesting to just drop that and put every star next to each other in the X axis regardless of the level right?

Yeah, firefox icon is just a temporary sprite
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Wed Dec 28, 2011 10:21 am

in that case use X for game level and Y for ID. That's not a bad idea because you then don't have to bother with star sharing the same ID in two different level.
So Array: Value at (Level,Star.ID) is good.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests