pandabear7413's Forum Posts

  • In my code:

    When the spacebar is pressed an enemy object is created, a corresponding enemyBox is created as well. But the enemyBox.speedMultiplier instance variable isn't getting set to the enemies.speedMutliplier value and instead is set to the default value (1). It's almost as if the enemies.speedMutliplier value hasn't been completely set in the spawnEnemy function before the 'on created' block is called.

    Can someone please explain why this is happening? Maybe it's a synchronization issue? I admit I don't understand sync / async very well.

    https://drive.google.com/file/d/1hOtJEhgl5agAFPPgpA222me8YH86wrU0/view?usp=sharing

  • I'm getting back into C3 after a few months and I'm definitely rusty. I'm getting some inconsistency in my new code and I think I may be picking objects incorrectly...

    Each enemy in my platformer used to just be a sprite, but to make things smoother I'm adding logic for an enemyBox 'anchor' sprite used for positioning and smooth movement. Each enemy sprite will now have a corresponding enemyBox object. The enemy and enemyBox sprite objects both have an instance variable called uniqueID, and it's this variable that ties them together.

    What's the best way to pick the enemy and enemyBox objects that have the same uniqueID? For instance I want the following code to position the enemy where its enemyBox is, but in certain situations enemies are placed on the wrong enemyBox. I believe this code may sometimes be picking the wrong enemyBox or just picking one at random. Is this the right/best way to pick an enemy object AND enemyBox object that have the same uniqueID instance variable?

  • You can set up 2 or as many los cones as you want...

    Ok now THAT I didn't know - gonna try it!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks. The challenge I've had w/ the LOS cone is that it only works for forward facing enemies. I.e., if I set the cone to be in the direction the enemy is facing, I can basically walk up behind them and I won't be in their LOS.

    I'm trying to implement a somewhat intelligent enemy AI, specifically:

    - they'll 'see' me from far away if they're facing facing me

    - if they're not facing me, they'll 'see' me when I'm closer, but I don't need to be right on them

    - if I shoot them from behind, they instantly know I'm there, regardless of how far away from them I am

    I guess this isn't really what LOS behavior is meant to accomplish, and it's more useful when trying to hide behind solid objects, etc. Just wondering if I'm missing something.

  • In my platformer game, I want the enemies to chase the player when:

    1) They are within range of the player (e.g., within 500 pixels)

    2) they are on the same platform as the player

    I can implement 1 with the LOS behavior, but that also makes the enemies follow the player if the player is on other platforms nearby. E.g., when the player walks underneath the enemy's platform and is within 500 pixels of the enemy, the enemy follows the player's movement.

    I've thought of an approach where each platform has an ID, and any enemy on that platform has the same ID, and when the player touches the platform they get that ID, etc, but that will get cumbersome quickly with lots of enemies and platforms. Is there a better way to do this? I'm sure it's been done many times before.

    Thanks

  • because it only tests the UID of the sprite with the lowest IID

    You're absolutely right, that's explains it perfectly. Thanks!

  • Seems like a simple question to answer, but I'm not understanding why my code is doing this...

    The only difference in the code below is:

    - in the 1st, it's comparing Sprite.UID > 1 (true for all 3 Sprites)

    - in the 2nd, it's comparing Sprite.UID > 2 (true for 2 of 3 Sprites)

    I would have thought that if it was true for ANY Sprite, the action block would execute. But it appears that the event 2 condition returns true (subsequently setting the 'result' and 'counter' variables) ONLY when the condition is true for ALL Sprites.

    Can someone clarify why it works this way?

    Thanks

  • because there's only one instance of the function object

    "function object"? As I understand it, functions aren't objects and they don't have instances. Instead, they're events. Per the docs:

    Functions are special kinds of events that can be called from actions. https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/functions

    But maybe I'm misunderstanding what you're saying...?

  • Thanks for the reply. I'm trying to understand what exactly are the rules for running functions against a picked set of objects.

    Actions always try to apply to one object. Without a condition, an action has no way to pick an object, so it applies to all objects.

    Per my 2nd post above, I believe the rule is: object-specific actions are run once for each object picked, non-object-specific actions run only once per event (regardless of how many objects are picked).

    But when you add a condition, the action gets some instruction. If the condition could be satisfied by multiple objects, it picks one at random. Adding "for each" forces the actions to repeat for each object that satisfies it.

    So in your top event, the function is only picking one random Sprite uid. If you add a "for each sprite" on that subevent, it should call the function three times.

    Re: "random", I'm guessing C3 doesn't pick objects at random. There are probably some rules it follows for to decide which object UID to pass to the function - e.g., it picks the object with the smallest UID. That's what my code does every time, it picks the Sprite with the smallest UID.

  • Let me take a stab at answering my own question: It's because calling the "move" function is not an object-specific action. Only object-specific actions (e.g., Sprite set animation) are called once per picked object. Actions that are not object-specific are only called once per event, regardless of how many objects are picked.

    Is this accurate?

  • Here’s my code. I have 3 Sprite objects, and all have state set to “good”. When I press the right arrow, “count” is set to 3 (i.e., 3 sprites are picked), but the “move” function is only called once with the UID of the first sprite create, so only that sprite moves.

    Can someone please explain to me why this code only calls the "move" function once, and not once for each object picked? Per the C3 docs: Another way to think about an event is "If all conditions are met then run actions on the instances meeting the conditions". https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

    I understand that adding a ‘for each Sprite’ condition before calling “move” will get all sprites to move, but I’m trying to understand why this is necessary.

    Thanks

  • dop2000 I get so pumped when I see you're responding to one of my questions, you are always spot on with your answers! This is exactly what I was looking for, and that tutorial from Ashley is gold. Thanks again!

  • Some context: I have a family called enemies, which is pretty established, and I wanted to create a new enemy type called Wolf. Wolf is very different from the rest of the existing enemies, which are mostly human-based, so I needed to develop lots of new code to control and animate Wolf. But in the end I still want Wolf to be a member of the enemies family as there’s common enemies code that will apply to Wolf.

    I wanted to avoid the existing enemies family code being called on Wolf during prototyping, as it would potentially throw everything off in the game and make prototyping a lot harder. So I chose to create a standalone object called Wolf to prototype. Even though it’s not part of the enemies family, Wolf has several identical behaviors and instance variables, like ‘health’ and ‘hitStrength’, and the Platform behavior.

    Now that I’ve got Wolf working (yay!), I want to add it to the enemies family. But because it has the same instance variable names as enemies, I need to change them before C3 will let me add Wolf to the enemies family. I expect this will involve a) changing the names of those IV’s in Wolf (e.g., change ‘health’ to ‘health2’), b) adding Wolf to enemies, c) changing the Wolf logic to use the IV’s from enemies (e.g., change anything referencing ‘health2’ to ‘health’), and then d) deleting the Wolf-specific IV’s ((e.g., ‘health2’). I’m probably going to need to do something similar with the common behaviors as well.

    This is just an example but it’s making me think there may be a better way.

    My question is, what’s a good way to plan for such ‘merges’ of code, and is there something I should have done differently? C3’s editing logic is great because it checks for errors caused by duplicate IV and Platform names, and I wish there was an easier way to do this merge without having to pick through my code. Any suggestions?

  • Thanks R0J0hound for the suggestion, similar to what I was thinking - but better!

    I was curious if there was a way to use elegant pick logic to do this in a 1- or 2-line event. I've seen some beautiful code suggestions in these forums that I never would have come up with, mainly because my brain just doesn't think that way.