Pick tile in array and change frame

Get help using Construct 2

Post » Fri Feb 03, 2012 11:37 am

I'm creating a 2D-Minecraft like game as a test and I'm a little stuck on this, the code below should change all tiles to frame 3 (a grey tile) but instead they all stay at frame 1. Why is that?

B
21
S
2
G
1
Posts: 90
Reputation: 2,146

Post » Fri Feb 03, 2012 2:51 pm

Actually, that should have worked, my guess is that it may need a tick to change the value,.... but you don't need to compare anything any way.
When you create the sprite, its already picked. So just drag the "Set animation frame 3" action up under the y loop.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Fri Feb 03, 2012 3:09 pm

Hm, well the reason for the seperate pick is for future code to come. If I drag "Set animation frame 3" to the Y loop it works, but when I set 3 to be the actual array entry it doesn't work!
B
21
S
2
G
1
Posts: 90
Reputation: 2,146

Post » Fri Feb 03, 2012 3:17 pm

It may be a bug. Might make a capx to confirm.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Fri Feb 03, 2012 10:49 pm

[code]+System: For "groundX" from 0 to worldWidth
Local variable pickUID=-1
+System: For "groundY" from 0 to worldHeight
    ->System: create object item on layer 0 at......
    ->worldArray: set value at (loopindex("groundX"),loopindex("groundY") to 1
    ->System: set pickUID to item.UID
+worldArray: value at(loopindex("groundX"),loopindex("groundY") = 1
+item: pick instance by UID pickUID
    -> item:set animation to 3[/code]

Two remarks:
1/ As far as I know, the item created is picked only in the action block in which it is created. In the next event only the picking by condition is used.
2/ 'Current value' as well as 'Current X', 'Current Y' and 'Current Z' should only be used in an 'Array foreach element' loop. That's what the "current" is about.Yann2012-02-03 22:54:33
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Feb 03, 2012 11:37 pm

Supposedly its the top tier that picks, and sub events to the creation tier should remain picked. So even though this is a sub event, its is the top tier as far as the tile being picked/ created is concerned.
It must be the array, its either not being initialized correctly, or possibly a non integer issue.
Edit:
Ahh didn't see the current for array, yeah don't use that with a loop.newt2012-02-03 23:52:16
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Sat Feb 04, 2012 10:21 am

Hm, right...well what's the solution I'm looking for then to achieve the same effect?
B
21
S
2
G
1
Posts: 90
Reputation: 2,146

Post » Sat Feb 04, 2012 11:12 am

Didn't you try what I wrote ?
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Feb 04, 2012 11:42 am

Oh sorry, didn't notice you posted fixed code (just thought you'd put my code in text rather than a screen!). Just tried it but nothing I'm affraid...

B
21
S
2
G
1
Posts: 90
Reputation: 2,146

Post » Sat Feb 04, 2012 2:46 pm

nest the 4th event under the 3rd event
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Next

Return to How do I....?

Who is online

Users browsing this forum: GUN, Yahoo [Bot] and 15 guests