Python: refer to instance from event

For questions about using Classic.

Post » Tue Sep 27, 2011 8:17 pm

Let's say I have multiple instances of a sprite object called box. I want each one to be destroyed when the user clicks on it. This is not difficult. I just make the event "On Left Clicked on box" and the action "box: Destroy". But what if I want to use a Python script in the place of the action? "box.Destroy()" doesn't work because it thinks I'm referring to box[0] no matter which box I clicked. So how do I specifically refer to the instance that triggered the event? I'm hoping for a solution that I can apply to any event or action, not just this particular example.

Thanks in advance.BillyTheBanana2011-09-27 20:21:50
B
2
G
1
Posts: 5
Reputation: 460

Post » Wed Sep 28, 2011 3:37 am

To destroy the first picked "box" Sprite use "SOL":
[code]SOL.box.Destroy()[/code]

To destroy all the picked "box" Sprites:
[code]for obj in SOL.box:
    obj.Destroy()[/code]

"SOL" stands for Selected Object List.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Wed Sep 28, 2011 5:11 pm

Thank you, that's perfect. Can you refer me to a more in-depth explanation of the SOL and what goes in it and when?
B
2
G
1
Posts: 5
Reputation: 460


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests