<SOLVED>Is there a better alternative?

0 favourites
  • 7 posts
From the Asset Store
Template for an alternative to falling shapes, fully documented in comments and video
  • 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.

    Thanks in advance!

  • 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.

  • Thanks for the response, ! 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!

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thanks for the demo, ! I do feel relieved now, editing the title to solved.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)