Remember picked objects having the same effect as Forget

For questions about using Classic.

Post » Fri Jul 23, 2010 6:59 pm

Hi,

I set up a function (DestroyBullet) to destroy instances of bullets (shot by the player). The function simply destroy the bullet object and spawn an explosion effect (an animated sprite, fading).

I used a similar function (exactly the same events used) when I destroy dead ennemies. For those, I used the option "Remember picked objects", so the function only destroy the one effectly dead, and it worked perfectly.

When I use the function on my bullets (they are destroyed when hitting a solid object or an enemy), with the exact same options, it doesn't, every time, ALL instances of bullet are destroyed, no matter what I use (remember or forget picked object).
If I copy/paste the two events of the function in the conditions that would normally trigger DestroyBullet (instead of actually calling the function), it work perfectly.

Have I did something wrong ?
B
1
G
2
Posts: 4
Reputation: 633

Post » Fri Jul 23, 2010 9:57 pm

Is your bullet object global?
B
3
G
2
Posts: 31
Reputation: 737

Post » Sat Jul 24, 2010 4:21 pm

Nop, neither the bullet nor the ennemies are global.

Got quite a similar problem today, I created a function with one parameter.
The parameter is an amount of damage, choose randomly at the call of the function, the function substract those damage from the ennemy and add it to the score.

When I used "forget picked object", all enemy where damaged together. So killing an enemy will make all of them blow up.
When I use "remembered picked object", sometimes only one dies, sometimes all of them, sometimes it seems they take only a part of the damage (may be it's due to the time when they were spawned).


I think I don't understand at all how it's suppose to work.

Is there a way to access a specific object in python ? I know that the "Enemy" variable works as a list, but how can I retrieve the exact enemy (well, the index) concerned by the event ?
B
1
G
2
Posts: 4
Reputation: 633

Post » Sat Jul 24, 2010 5:01 pm

It's hard to tell without a cap, but I guess it is a picking problem, not the function object working incorrect.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Jul 24, 2010 5:26 pm

The two events picking bullets are :

- On collision between Bullet and Enemy
- On collision between Bullet and Solid

Is that the problems ?

I'll upload the cap at the occasion, but it's quite a mess as it's my first project and I already got a lot of event and pieces of scripts. :lol:
B
1
G
2
Posts: 4
Reputation: 633

Post » Sat Jul 24, 2010 7:27 pm

Are you using call function after delay?
Image Image
B
161
S
48
G
91
Posts: 7,357
Reputation: 67,269

Post » Sun Jul 25, 2010 3:41 am

newt's question plus:

"may be it's due to the time when they were spawned"
Are you spawning them in the same tick, when trying to access a pv of the enemies? Sprites are created at the very end of a frame. Maybe that is causing problems in some situations, because the function call takes place the moment you call it.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jul 25, 2010 9:33 am

[quote="newt":2cxrdmrb]Are you using call function after delay?[/quote:2cxrdmrb]

Nop, simple call function.

[quote="tulamide":2cxrdmrb]newt's question plus:

"may be it's due to the time when they were spawned"
Are you spawning them in the same tick, when trying to access a pv of the enemies? Sprites are created at the very end of a frame. Maybe that is causing problems in some situations, because the function call takes place the moment you call it.[/quote:2cxrdmrb]

Enemies are spawned randomly every x milliseconds, it's not tick based i think.

Bullet are spawned every 100 ms if mouse button is down.
B
1
G
2
Posts: 4
Reputation: 633

Post » Sun Jul 25, 2010 5:04 pm

[quote="Zevka":4jutqfvc]
Enemies are spawned randomly every x milliseconds, it's not tick based i think.

Bullet are spawned every 100 ms if mouse button is down.[/quote:4jutqfvc]
I still think that this is the problem when picking the objects. You have to make sure the sprites are already created before you can safely access them (e.g. to access a pv of sprite x, you need to wait at least one frame after sprite x was spawned)

If I recall right, the timing conditions are dependent of the frames whereas the function object has its own timing. That could lead to situations where your order of events is right, but they are still executed in another order. When spawning and accessing a sprite meet in the same frame it does simply not work, without an error message or debugger salience.

I can't help with python, but I used a trick for the functions (delaying the access to a sprite by at least 1 tick) to avoid that problem in my auto zoom engine. Maybe you can integrate and adapt it. (you find the events of interest in "Camera Control":"HighLevelFunctions":"Camera Creation/Deletion" plus event 14 of "Camera Control":"LowLevelFunctions")
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests