Instance picking ideas

New releases and general discussions.

Post » Mon Sep 29, 2008 10:47 am

Hello.

I posted already this: viewtopic.php?f=16&t=1667 in uploads forum, but I got the feeling that people kind of ignored and missed it. So, I'll post now my instance picking ideas and some new thoughts here.

First of all, Consturct needs improved picking of object instances. The problem is currently that when there is two instances of the same object interracting in same event, user is unable point out which instance does he mean.

For simple example, let's have a game where there is creatures, and bigger creatures eat smaller, as they collide. The smaller thus destroys and the bigger gets even more bigger. A game this simple is relatively easy to make using different ways, but the most simple, intuive way would be addressing the two creatures with different names. We say that creature A is the bigger and B the smaller, and then describe that creature A does this and creature B does that. This is a feature that Construct doesn't currently support with different instances of same object.

A code example of would-be syntax:
[code:3vawz0gi]Sprite1.A Collides with Sprite1.B
+Sprite1.A.Value('Size') > Sprite1.B.Value('Size')

>> Add Sprite1.B.Value('Size') to Sprite1.A.Value('Size')
>> Sprite1.B Destroy
[/code:3vawz0gi]
Notice that the names aren't predefined for specific instances, they are assigned as the event performs, and discarded after, when SOL is discarded also.

There is a workaround, which I use in my thread on Uploads forum and which David uses (viewtopic.php?p=11456#p11456), and which some other use in those gravity simulation threads etc. This workaround uses families, it represents a specific instance of an object with one family and another instance with another family. It works fairly well... but it is and feels still a workaround.
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Mon Sep 29, 2008 11:04 am

Secondly, an idea about a faster, new type of loop, "For Each Pair". I got this idea when reading a thread about gravity simulation (viewtopic.php?f=3&t=1627&st=0&sk=t&sd=a) In gravitation calculations, you must loop trough every object pair, because every object casts a force to every object. Traditionally you would do this with nested for each loop, which is unfortunately really slow. The gravitation simulation uses a loop where every object is tested with every object. This is a very common special case of nested loop, and I think that it could be TWICE faster!

A nested loop. Numbers are object instances and I means that the looping event is tested with instances of it's column and row.
[code:39e3huh9]
1 2 3 4 5
1 I I I I I
2 I I I I I
3 I I I I I
4 I I I I I
5 I I I I I
[/code:39e3huh9]

"For Each Pair" -loop. A new kind of loop which would perform about twice faster. O means that the looping event is not tested with the instances of it's column and row.
[code:39e3huh9]
1 2 3 4 5
1 O I I I I
2 O O I I I
3 O O O I I
4 O O O O I
5 O O O O O
[/code:39e3huh9]

So, it runs through every PAIR of instances only one. I.e. if it has already tested and performed the event with instances 1 and 3, it won't do so again with instances 3 and 1. On top of that, it doesn't perform the loop with the instances 1 and 1, in other words, the same instance (well, this could be an optional choise). "For each pair" -loop could use "instance naming" described above.

[code:39e3huh9]For each pair of Asteroid (A and B)
>> Set global('TempForce') *force calc here*
>> Asteroid.A.[Physics].AddForce global('TempForce') towards Asteroid.B
>> Asteroid.B.[Physics].AddForce global('TempForce') towards Asteroid.A
[/code:39e3huh9]

In theory, an loop like this, when optimised propely, would be a little over twice (minus overhead) faster than a nested loop, because the operations are done for every object pair, instead of every object... It's impossible for me to say would it really be significantly faster in Construct if implemented, but it might be worth of testing.

Finally, some other picking thoughts... Does "Pick random" pick randomly from the current Selected Object List or from all objects? I experienced some difficulties with it when trying to get it pick from SOL. It SHOULD pick from SOL, shouldn't it? Also, "Pick n objects randomly" would be nice.

Then about forgetting SOLs... currently the function object is the only way to forget a SOL inside an event. I think that this is such a basic functionality that using Function object feels like a workaround... How about option of forgetting SOL in subevent? Or something like that.

Oh, one more: Did construct suppor arrays internally? (Haven't used them and I am on comp that doesn't have Construct now) If so, whould it be possible to save and load object selections to and from arrays? Would speed up and simplify certain things, and allow even easier debugging with selections issues.
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Mon Sep 29, 2008 11:20 am

I really like the first idea, if it's possible.
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Mon Sep 29, 2008 3:36 pm

[quote="Drasa":16n117d2]
A code example of would-be syntax:
[code:16n117d2]Sprite1.A Collides with Sprite1.B
+Sprite1.A.Value('Size') > Sprite1.B.Value('Size')

>> Add Sprite1.B.Value('Size') to Sprite1.A.Value('Size')
>> Sprite1.B Destroy
[/code:16n117d2]
[/quote:16n117d2]

Why have Sprite1 in the actions at all? It would be more useful if when a collision event is made the first object is named A and the second is named B so it would be like this:

[code:16n117d2]Sprite1 (labelled A) Collides with Sprite1 (labelled B)
+A.Value('Size') > B.Value('Size')
(Sub-event so it uses the objects picked in the main event)
--------->> Add B.Value('Size') to A.Value('Size')
--------->> B Destroy
[/code:16n117d2]
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon Sep 29, 2008 5:43 pm

Jayjay: LABEL! Yes, that's the word that fits the purpose. Thanks for the term.

About multiple picking conditions: Lets have two Sprite1s, UID 2 with 'Size' 4 and UID 4 with 'Size' 7. that "Sprite1 (labelled A) Collides with Sprite1 (labelled B)" must work so that both A and B pick both UID 2 and UID 4... That's because if it picks directly one instance there is no way to test further differences between A and B in following events. So, after the collision condition A = (UID2, UID4) and B = (UID2, UID4), and after the "A.Value('Size') > B.Value('Size')" condition A = (UID4) and B = (UID2).

There's some problems if user wants to do so that whichever sprite destroys is chosen randomly... or something like that. If there's a "Pick randomly" condition to rule out other instance in A, how are we going to make so that the outruled instance is conserved in B and the other is ruled out?

My answer would be that there was an condition like "Exclude A from B". This would be useful tool in many other situations also, when it's easy to define what the other label consist of, and after that just make B to be "not A"...
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Mon Oct 06, 2008 3:11 am

I think i'm having a similar problem, i have multiple instances of the same object, each one has a different height value
if the player is overlapping more than one of them, even though i put an event in that picks the object by it's highest height value, it STILL picks the one that was created first, NOT the one with the highest value.
I dunno if it's related or not to your problem, to be honest i'm watching heroes and didn't read all the walls lol
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Mon Oct 06, 2008 5:32 am

[quote="Arcticus":20ogf976]I think i'm having a similar problem, i have multiple instances of the same object, each one has a different height value
if the player is overlapping more than one of them, even though i put an event in that picks the object by it's highest height value, it STILL picks the one that was created first, NOT the one with the highest value.
I dunno if it's related or not to your problem, to be honest i'm watching heroes and didn't read all the walls lol[/quote:20ogf976]

That sounds like a bug (or a coding mistake)... My "problem" is just a feature request. Maybe you could show a cap?
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Mon Oct 06, 2008 6:34 am

i'm pretty sure it's not a coding problem, since it's like:
If player if overlapping obstacle
pick obstacle with highest Height value - change player value to some other value

and even if i take the pick event out, the exact same thing happens, basically it depends which object i put on the layout first, which makes me assume it's a UID problem

I'm pretty sure i uploaded a cap somewhere, either uploads or help, i've temporarily fixed my problem though by putting the obstacles with the higher values on the layout first, followed by the smaller ones
B
3
S
2
G
5
Posts: 351
Reputation: 2,377


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests