[solved]Trouble with event/trigger once

For questions about using Classic.

Post » Wed Sep 07, 2011 4:23 pm

I can't solve this:

wish:
When a self firing weapon(/turret) runs out of ammo, it reloads. After reloading it can fire again.
Problem:
With more than 1 weapon on screen, they start to synchronize (unwanted result) after 1 reload and reload and fire bullets at the same time.
(1 weapon on the screen works fine)


+ Weapon: Value 'ammo' Equal to 0
   + System: Trigger once*
   -> System: Create object reloading on layer 1 at (Weapon.x, Weapon.y)
   + reloading: Animation "Default" finished
   -> reloading: Destroy
   -> Weapon: Set 'ammo' to 3

* when I don't use "trigger once", it keeps creating sprites, because ammo stays "0" for several seconds. But this way, it creates only 1 sprite "reloading" for 1 weapon, while there are several weapons on the screen.

(CC v0.99.84)rogerty2011-09-07 23:35:35
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Wed Sep 07, 2011 4:33 pm

It's hard to tell exactly what the problem is without a cap. The Trigger once is easily replaced with a private variable. Call it "Reload Time".

+ Weapon: Value 'Reload Time' Equal to 0
   -> Weapon: Set 'Reload Time' to -1
   -> System: Create object reloading on layer 1 at (Weapon.x, Weapon.y)
   + reloading: Animation "Default" finished
   -> reloading: Destroy
   -> Weapon: Set 'ammo' to 3
   -> Weapon: Set 'Reload Time' to 3

Every time you subtract from Ammo (When you shoot i guess) just subtract 1 from Reload Time as well.
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Wed Sep 07, 2011 4:57 pm

Thanks for the reply.

With your suggestion it doesn't execute/look at the subevent ("reloading: Animation "Default" finished).


(Tried in CC 1.2 as well)rogerty2011-09-07 16:57:36
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Wed Sep 07, 2011 5:31 pm

It is synchronizing because Weapon and reloading are not paired.

The sub-event:
+ reloading: animation "default" finished
is picking that one reloading object and all the Weapons with an ammo of 0.

To fix you need to pick the Weapon that you want paired with reloading. You could use a variable with UID or since it appears that your weapons don't move you can pick the Weapon that is in the same location as reloading.

+ Weapon: Value 'ammo' Equal to 0
   + System: Trigger once
   -> System: Create object reloading on layer 1 at (Weapon.x, Weapon.y)
   + reloading: Animation "Default" finished
   + Weapon: X Equal to reloading.X
   + Weapon: Y Equal to reloading.Y
   -> reloading: Destroy
   -> Weapon: Set 'ammo' to 3
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Wed Sep 07, 2011 10:58 pm

R0J0hound, that sounds so right, but it didn't work.

update:
Now I'm trying to figure out the first part first:
assigning every weapon that runs out of ammo a reloading-sprite, because it seems that the "trigger once"-condition gives the unwanted result: only applying it to 1 weapon.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Wed Sep 07, 2011 11:05 pm

Just Upload the .cap and I think this will be solved very quickly by some random clever mod.

Use this site if you don't wan't to register or do anything else, Really fast.

http://yourfilelink.com/
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Wed Sep 07, 2011 11:29 pm

Thanks Nifl, for the offer, thinking and earlier post.

I'm glad I just got it working! (thanks to R0J0hound's suggestion of UID's)

event 1
+ Weapon: Value 'ammo' Equal to 0
+ Weapon: Value 'Reloading' Equal to 0
-> System: Create object reloading on layer 1 at (Weapon.x, Weapon.y)
-> reloading: Set 'WeaponUID' to Weapon.UID
-> Weapon: Set 'Reloading' to 1
event 2
+ reloading: Animation "Default" finished
+ Weapon: Unique ID is reloading.value('WeaponUID')
-> reloading: Destroy
-> Weapon: Set 'ammo' to 3
-> Weapon: Set 'Reloading' to 0

This simple event took me 3 hours, I think.

When R0J0hound mentioned pairing, I thought I could use the Container feature/property, but it didn't work or I didn't know how.
If there's a more quicker/elegant way to achieve the above result, I am interested.rogerty2011-09-07 23:36:56
B
16
S
5
G
7
Posts: 599
Reputation: 5,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests