Code doesn't work as intended all of a sudden! Please help

0 favourites
  • 11 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hi everyone!

    An event that adds a numerical value (in this case, it's 1) to a variable everytime an object is "picked up" (overlapped by player sprite and then destroyed) has started to multiply the numerical value by 4.

    Here is the code in text form:

    [RainbowCoin Behaviour]

    ----+ Sprite: On collision with rainbow

    ----+ Sprite: Is overlapping Overlays

    -----> Overlays: Add 1 to OverLayColour

    -----> rainbow: Destroy

    It used to work fine, now it multiplies the 1 in Add 1 to OverlayColour by 4 for no discernible reason.

    If I change the numerical value to 0.5, it adds 2 to the OverlayColour variable, which is consistent with the 'multiply by 4' hypothesis.

    The OverlayColour variable is a Family Variable. To test whether the family variable was causing the issue, I changed the event to affect each individual overlay, but the result was the same: still multiplying by 4.

    I can't figure out why the event is suddenly reacting this way: I believe that there aren't any other events that contribute to this problem. Of course, there is a reason for this, so I need help finding it!

    Here's a link to the project file:

    drive.google.com/file/d/1nV3xU6mORatAc3GX--JUzS1QB_4kpAtU/view

    Let me know if you try to download it and it fails for some reason.

  • No access to the file.

  • Hi Igor, you now have access to the file, cheers!

    So does Ant K. I'll grant access when you request access, cheers!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I studied your source code.

    I think the collision trigger has time to work several times before the object is deleted.

    I noticed such small problems with collision processing speed after some update.

    To fix it, add disabling collision as I showed in the screenshot.

    More on your game, you just do not get too upset. If the game for the PC, everything is fine. But if the game for smartphone, it takes extra resources and battery power. You have too many events every tick and just events without a trigger. It's not a problem, but you can do better.

  • It's because there are 4 player Sprites on top of each other.

  • thankyou thankyou thankyou thankyou!!!!!

    igortyhon - thankyou for looking at it and I will keep your suggestions in mind regarding mobile.

    lionz - i haven't had the chance to check that this is the case but it makes sense that this would cause the issue - so thanking you in advance!

    Not sure how I managed to create 4 of the same sprite (unintentionally) but stranger things have happened :)

    Thanks again!

  • I can now see how I managed to create an additional 3 player sprites, I did it by accident when copying and pasting an unrelated sprite.

    Thanks once again everyone!

  • It's because there are 4 player Sprites on top of each other.

    Exactly!

    You're right, I wasn't paying attention and didn't notice such an obvious reason!(

  • > It's because there are 4 player Sprites on top of each other.

    Exactly!

    You're right, I wasn't paying attention and didn't notice such an obvious reason!(

    igortyhon to be fair the sprites were hidden off screen and hidden behind a layer in the editor! I didn't even know they existed lol

    By the way Igor I was thinking about what you said regarding Events with no triggers and 'Every Tick' events slowing down performance on mobiles. What would you suggest instead of these?

    Currently the app is working fine on my phone but ofcourse as the project develops, I don't want to run into performance issues.

  • I will mark on the screenshot the events with which you need to be careful (red).

    For example you are checking if an object has left the sheet to delete it. If there is no green arrow next to the action then this event will be checked every tick about 60 times per second. But we don't need it that often.

    We can check once per second these objects and delete (green).

    And for example updating the text, you don't need to update the score every tick. You can do that after you get the score. Or every 0.3 seconds.

    And you can take that into account when building more complex games. On this small game, all of this optimization will not be noticeable.

    For example, I have groups with Boss behavior and they are inactive. But after spawning the boss I activate them.

    Of course there are events that have to be handled every tick and without this there is nowhere to go! For example the position of the camera and other motion objects...

  • cheers igortyhon, this makes perfect sense and I'll optimise as many "every tick" events as I can :)

    i've been getting a lot of feedback on my coding practices recently and I really appreciate it, thank you!

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