Fire delay when looping through gamepads?

Get help using Construct 2

Post » Wed Jan 01, 2014 7:45 pm

I have a local multiplayer game I've been working on, but have hit a wall on a bug for players firing projectiles using gamepad analog sticks.

Basically, I have a variable on each player that contains a playerID that corresponds to a gamepad. If the right analog stick is about a value, the player should fire at a set firing rate.

The problem I've run into is that it only seems to work for the lowest-numbered player/gamepad. That is, if player 1 is firing, players 2-4 can't fire. If player 2 is firing, players 3 & 4 can't fire.

Here's the event sheet below:




Note that the playerShooting events are for testing purposes to see if an individual player is firing. It shows that they are, yet the issue with firing remains so long as there is a delay. If I remove the delay, however, all players can fire individually, so it's something to do with the "every x seconds" event, though I can't think of a better way to do the delay.

Any hints or suggestions would be greatly appreciated. Thanks!
B
70
S
40
G
24
Posts: 517
Reputation: 20,068

Post » Wed Jan 01, 2014 11:14 pm

Seems like if could be the OR block. For example, if Player 1 is firing, the first condition in the OR block is met, so it won't continue going through the OR block to see if the other players are firing. That's why Player 1 can probably fire if 2-4 already are, and all players can fire is Player 4 is (assuming they start in reverse order: 4, then 3, then 2, then 1).

Make each one a separate condition and see if that works.Clowerweb2014-01-01 23:16:12
B
15
S
4
G
4
Posts: 11
Reputation: 3,488

Post » Thu Jan 02, 2014 1:04 am

Thanks @Clowerweb. That's exactly what I was trying to avoid having to do, but if that's what it takes, so be it. Also, it does work properly when there isn't a delay between spawning the projectiles, so...that's weird.

I was hoping the For Each block would handle each player separately, as that's how I thought it was supposed to function...maybe that's not the case?digitalsoapbox2014-01-02 01:09:27
B
70
S
40
G
24
Posts: 517
Reputation: 20,068

Post » Thu Jan 02, 2014 1:05 am

Give it a try and let me know how it works out. I'm not 100% on it, but it makes sense that that's what's going on based on my experience with general programming (it's doing what an OR block should do - if one of the conditions is met, it should ignore every condition after it and execute the block).

Tip: Make a function for all the stuff that the current block you have is executing. Then you can just call the function instead of having all that code repeated for each player.Clowerweb2014-01-02 01:10:07
B
15
S
4
G
4
Posts: 11
Reputation: 3,488

Post » Thu Jan 02, 2014 1:30 am

Still the same issue, plus I've just ended up with duplicated code. I think I just need to find another way to do the delay, hopefully without recreating the events for every potential gamepad.

Oddly, doing player movement in the exact same way works perfectly, as does creating projectiles without any delay between them - it's just anything with a timer on it that breaks.

[QUOTE=Clowerweb]
Tip: Make a function for all the stuff that the current block you have is executing. Then you can just call the function instead of having all that code repeated for each player.[/QUOTE]
The way it's working now doesn't have it duplicated for each player, and I'm pretty sure calling a function every tick for each player to check for continuous input wouldn't be any more efficient than the way it's set up in the OP.digitalsoapbox2014-01-02 01:35:20
B
70
S
40
G
24
Posts: 517
Reputation: 20,068

Post » Thu Jan 02, 2014 5:12 pm

Bumping this in case anyone else has any ideas on what the issue may be.
B
70
S
40
G
24
Posts: 517
Reputation: 20,068

Post » Thu Jan 02, 2014 5:25 pm

The for each and every x seconds are probably somehow in conflict.

why not give each player a timer behaviour and add an on timer function instead. The engine will check every tick for each player if the timer is ended, if so you set the timer again for player.projectilerate seconds.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jan 02, 2014 5:31 pm

Also putting the every x seconds condition above the or-block could make a difference, but I'm not completely sure about that.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 03, 2014 12:41 am

[QUOTE=LittleStain] Also putting the every x seconds condition above the or-block could make a difference, but I'm not completely sure about that.[/QUOTE]

The OR block is for player input that should be checked continuously, so I don't think it'd make sense to reverse that. Tried that originally, but I'll try the local timers suggestion - thought about it, wanted to avoid it, but it's better than it not working. The issue seems to be linked to the every x seconds, since it works fine without any delay in place.

Thanks!digitalsoapbox2014-01-03 01:47:19
B
70
S
40
G
24
Posts: 517
Reputation: 20,068

Post » Fri Jan 03, 2014 7:43 am

Why would the or block have to be checked every tick, when it can only affect anything every player.fireratio seconds?

Or are you planning to add more code to the block?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: Madave96, RobertMKD, Yahoo [Bot] and 7 guests