iterate through all instances

New releases and general discussions.

Post » Thu Mar 05, 2009 8:57 am

How do I iterate through all instances of an Object

if I do

Meteor.X += 1

only one of my Meteors moves.

And as someone mentioned in another post. Picking support in python. Do something with all picked objects or... pick and unpick objects.
B
4
G
3
Posts: 46
Reputation: 992

Post » Thu Mar 05, 2009 3:32 pm

System: For Each Object

But just in case you don't need to, might I suggest you post a description of the type of movement you want for your meteors? You might not need to do a loop at all. Depending on what you want them to do there could be an alternate method.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Mar 05, 2009 7:42 pm

Thanks for trying to help me out.

The quetion is not so much on the actual movement but on how to access individual object instances and all object instances. In Python that is.

I am able to find a For each Sprite in python.

It would have been natural for the python part to be able to iterate over all Sprites using something in the lines of
[code:38rp9999]
for instance in Sprite
instance.X += 1
[/code:38rp9999]

or something like
[code:38rp9999]Sprite[index] += 1[/code:38rp9999]

Another option would be to use the event picking mechanism and execute the python script as part of the action. Would that be possible. I think it would be a nice option to have the python script as an action of some event.
B
4
G
3
Posts: 46
Reputation: 992

Post » Fri Mar 06, 2009 12:58 am

Davo, what's the syntax for this?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Fri Mar 06, 2009 6:31 am

I believe it was

for instance in Sprite
instance.X += 1;

I implemented the elements thing in the classes so object types were iterable, but I cant remember if the above is the syntax, I'll check when I get home and hopefully get back to you
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Fri Mar 06, 2009 7:53 am

for instance in Sprite
instance.X += 1;

Looks natural. But I cant get it to work. I hope that im doing something wrong :-)
B
4
G
3
Posts: 46
Reputation: 992


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests