Is there a difference in picking within Functions vs Custom Actions?

0 favourites
  • 7 posts
From the Asset Store
Electric Cage
$2.40 USD
60% off
Dodge electric balls and survive in an unpredictable spaceship within an electric cage!
  • I randomly found a quirk when I was switching an existing function to be a Custom Action. The game is a 2D shooter with the player able to face either left or right and fire projectiles along the horizontal plane.

    The events pictured above, named "spawn_Projectile", both do the exact same thing: spawn a bullet sprite "Dart_Default" on the image point of a weapon sprite, set a damage variable, and then check to see if the Player is mirrored, and mirror the bullet accordingly. The code worked perfectly fine when it was originally inside a function.

    The funny thing is that when I first copied the code from the Function to the Custom Action I got a bug. If the player fires a bullet in the non-mirrored direction (right), then turns and fires a second bullet in the mirrored direction (left), and the first bullet is still on the screen, then the isMirrored toggle will apply to BOTH projectiles, the one just spawned from the barrel of the gun and the one still in flight.

    It caused some pretty cook telekinetic like visuals, where I can instantly change the direction of bullets mid-flight by shooting in the opposite direction and have a whole swarm of bullets bouncing back and forth across the screen.

    Still I had to fix it, and found that adding a "Pick Last Created (Dart_Default)" solved the problem. But why? That Pick Last Created is the only difference between these two events, other than the fact that one is a custom action and one a function. Is there some Picking rule that is unique to either? Does it have to do with the fact that the dart objects were recently created within the event?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'd imagine your bug would be present in the function version too. Auto picking by newly created objects isn't preserved in a separate same-level event afaik. Try putting the pick mirrored condition in a sub event of the spawn event.

  • Yes, there is a difference between Functions and Custom Actions:

    Functions are predefined operations that perform specific tasks and return a result. They are often used to handle calculations, data processing, or logic within a workflow.

    Custom Actions are user-defined tasks that execute specific actions, like triggering events or changing settings. They don't necessarily return a value but instead perform an operation, such as updating an interface or calling external resources.

    In short, Functions focus on logic and return values, while Custom Actions focus on performing operations within the system.

  • Auto picking by newly created objects isn't preserved in a separate same-level event afaik

    I had no idea about that rule. Is there someplace in the manual or a blog that outlines some of these finer details of picking?

    As you said, as soon as I nested the the mirrored condition and Set Flipped action underneath then I didn't need the pick last created.

    But still, the function worked without being nested. Do the picking rules change for Functions maybe?

  • construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

    Picking resets between events

    After an event ends, the next event begins from scratch. Its conditions will start picking from all instances again.

  • Spiceuser - your post reads like it was AI generated (sounds plausible but is actually mostly unhelpful or wrong). Please don't use AI to generate posts - see the Forum & Community guidelines.

  • oosyrag Thanks for the link!

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