<SOLVED>Is there a better alternative?

Get help using Construct 2

Post » Fri Aug 12, 2016 4:31 pm

Not trying to be picky, but using a boolean per each of these is quite annoying. I know it can be done with the Timer behaviour, but I just can't figure it out.

Is it even worth it? Does having a huge number of booleans/variables on an object with many instances affect performance? Would love some insight about this, since I've been looking through the forum and found no real solution, just ideas.

Image

Thanks in advance!
Last edited by CloveltOc on Fri Aug 12, 2016 9:16 pm, edited 2 times in total.
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Fri Aug 12, 2016 4:59 pm

@CloveltOc -

First, I think in some cases the timer behavior is better to use & easier to make. But in this case, the Every(X) seconds condition is good for this situation.
Second, Wait() in a "for each loop" seems wrong, this definitely needs a timer / Every(X) seconds condition.
Third, The way you made the events with the shooting boolean is a bit inefficient. Why?

"It's because a loop runs in every tick... that means the boolean (shooting) will keep changing to true/false in every (1/2 * tick). That's inefficient for me. But again since
today's devices are too fast as Ashley said, it won't matter. But then again, since it's a loop then it will matter. "


I recommend you change it to this instead using the Every(X)Seconds condition.

*For Each (Ship)
*Every(ship.fireRate)
------>Function Call "shoot (ship.UID, 0, ship.spread)

Hope that clears it up.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,111
Reputation: 59,145

Post » Fri Aug 12, 2016 6:15 pm

Thanks for the response, @chadorireborn ! But I had previously invested some time and tried the same alternatives, which aren't working for me (at least in my case).

First, using "every X seconds" with "for each" will only trigger the event on the first instance of the family (the picture is actually wrong, it's a family), as it is said in this post. The solution I currently use came from this post, which doesn't even use families, but has a similar structure.

Second, using the "every X seconds" will not even work as intended, because then the player would be able to skip cooldown time and shoot twice, which would be way too op for long cooldown weapons. Let me explain:
-Blaster (5 second cooldown)
·Wait 4.9 seconds
·When fire is pressed twice 0 and 0.2 seconds later, it will have skipped 99% of it's cooldown time on the second shot.

Third, this is the exact reason why I was looking for a better solution, but it seems like it is timer or nothing...

But again, thanks a lot for the response!
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Fri Aug 12, 2016 6:37 pm

From the manual :

"Using too many loops
This is rarer, but using too many loops like For, For Each and Repeat can cause the game to slow down. Nested loops are especially likely to cause this. To test if this is the problem, try temporarily disabling the looping events."

I don't think this for each loop is going to affect the performance, it's more likely going to be the number of ships you have loaded in memory. You can check if it is having an effect using the debug mode. Since you are updating variables here and not, i.e. the size of the ship or lots of textures at once, I don't think it's going to matter for performance.
B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Fri Aug 12, 2016 6:54 pm

Yup, I checked and there's not much of a difference using "for each" or not, as I said I'm more worried about the quantity of instance booleans affecting performance. There will be many ships running at the same time, without having in mind AI, etc. That's why I'm making this post. Still looking for the answer, though.
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Fri Aug 12, 2016 8:19 pm

I set up 1000 sprites that all toggled 5 boolean variables every tick and the FPS was fine, CPU usage went up very slightly but yeah this is an extreme example.
B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Fri Aug 12, 2016 9:15 pm

Thanks for the demo, @plinkie ! I do feel relieved now, editing the title to solved.
B
9
S
3
Posts: 150
Reputation: 1,264


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher, zsoldiers and 6 guests