How do I destroy a background by Index ?

Get help using Construct 2

Post » Wed Mar 08, 2017 6:56 pm

If the condition is something like

backgroundabc(1).x > 400 => "destroy backgroundabc"

destroys all backgroundabc instances

but i would like to destroy just (1) ... is there a possibility to get the index in destroy commands ?

same goes for similar operations, like set position - i dont find a way to specify the index number
B
9
S
3
G
4
Posts: 58
Reputation: 2,799

Post » Wed Mar 08, 2017 7:40 pm

You dont pick the Sprite. You have to pick. Always.

System > Pick all > backgroundabc
System > Pick nth instance > backgroundabc ... 1
Sprite > Compare X > 400

Why pick all ? I wrote it there for the logic.
Index, or the expression Sprite.IID, or 'nth' in the condition, or sprite(n).Expression ...... , all stand for the index in the picklist. Always does.
If it is a root event, you dont need to explicitly use 'pick all', you can assume that they are all picked (like in in your case, when you dont explicitly pick em, you delete them all)



This will not work as you intend. (to illustrate IID)

Sprite > Compare X > 400 (picks all sprites with x > 400)
System > Pick nth instance > Sprite ... 1 (pick the second sprite in that pick list, but that picklist is not containing all sprites anymore, just does with X > 400)



Not sure though why you need IID.

Sprite > Compare X > 400
_____ destroy

Should just do fine.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Mar 08, 2017 8:13 pm

Thank you - it works - but i dont like the syntax

now i got

{Event} Pick TiledBackground instance 3 -> {Action} Destroy Tiledbackground

which destroys just instance 3 - which is what i wanted - but from a syntax perspective i think it would be more fitting if it was ->

{Event} Pick TiledBackground instance 3 -> {Action} Destroy Tiledbackground instance 3
B
9
S
3
G
4
Posts: 58
Reputation: 2,799

Post » Wed Mar 08, 2017 8:31 pm

Plz read https://www.scirra.com/manual/75/how-events-work

The syntax perspective is pick, pick, pick pick & pick, run actions on picklist.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Mar 08, 2017 8:41 pm

Ok, I understand - pick, pick, pick -
B
9
S
3
G
4
Posts: 58
Reputation: 2,799

Post » Wed Mar 08, 2017 8:54 pm

It' still bad syntax

{Event} Pick TiledBackground instance 3 -> {Action} Destroy Tiledbackground instance 3 - would be correct

if i enter

{Event} Pick TiledBackground instance 3 -> {Action} Destroy Something_Else

something_else is destroyed - although it has nothing to do with the TiledBackground instance 3

---

and yeah, i know - pick, pick, pick
B
9
S
3
G
4
Posts: 58
Reputation: 2,799


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests