pandabear7413's Recent Forum Activity

  • In my platformer, my enemies will not 'see' the player from far away. But when the player gets close enough they will see the player. And once they do, I want them to follow the player until they are killed.

    I was hoping to use the following code. I want to use 'trigger once' to keep this code from running every tick for each enemy once they have the increase LOS range. But 'trigger once' makes it so that this code only runs for the first enemy that sees the player. I know I can use an enemy instance variable like 'seesPlayer' and set it / check for it, but I'm all about keeping IVs to a minimum (I have so many already).

    Is there a way to write this code so that it runs only once for each enemy object?

    Thanks

  • Ok I think I figured this out:

    pick enemies

    for each enemy

    pick enemyBox by comparison (enemyBox.uniqueID = enemy.uniqueID)

  • (moved this from the general discussion forum)

    I have an enemy object type and an enemyBox object type. Each enemy object has an associated enemyBox object, and they both have a uniqueID instance variable that ties them together. In other words, an enemy and an enemyBox are related if enemy.uniqueID = enemyBox.uniqueID.

    Here's what I'm trying to do. I start off with a subset of enemyBoxes, for example: pick all enemies on a given platform. From that subset, I want to pick all of their related enemyBoxes. In other words, pick all enemyBoxes that have a uniqueID matching a uniqueID from the previously picked enemies.

    How would I code that in C3? It's the bold part that's throwing me off.

  • You do not have permission to view this post

  • Yeah I get what you're saying. But I do have lots of logic that makes decisions based on animation state (when the collapse animation ends, when frame 2 of an animation is played, etc), so even if I moved all the data over to the enemyBox object, they'll still be plenty of instances where I'll need to get data from the associated enemy object.

    I have 1 year's worth of code where enemy was the only object, and I recently determined I need to have an enemyBox object for positioning. Live and learn. Thanks for the help!

  • Not really understanding the problem here? If you want to create a specific enemy then you have to pick that enemy anyway, nothing to do with families. If the animation object is in a container with the enemy then great.

    Here's one scenario: When an enemyBox is hit by bullet, stop enemyBox's motion (using platform behavior) and reduce enemy's health

    Let's assume the enemy object has the relevant enemy data in instance variables (health, speed, power, etc), and the enemyBox object has positioning info, collision polygon, and Platform behavior. And the enemy and enemyBox are in a container.

    If I was able to use enemies and enemyBoxes families and put them into containers together, I can write the above with a single condition and 2 actions and it will apply to all enemy types. But because I can't use families with containers, I need to write this code block specifically for every enemy type.

    There are tons of places in my code where I leverage families for actions to apply to all enemy types, so I foresee the issue above being replicated many times.

  • If you are going to use many objects then it looks like you don't need to make a separate enemybox object for enemies, you should just use one object. I don't know what its use is but I can't imagine you need different objects.

    I was thinking the same thing. The enemyBox is just for positioning and movement, so I was first thinking to have a single enemyBox object with 1 animation (and collision polygon) per enemy type. But and you can't have an object (i.e., the enemyBox) belong to multiple containers, so instead I was planning to create an enemyBox object type for each enemy type and then put the 2 in a their own container. But since containers cant be used for families, it looks like the best option is to use my family of enemies with a single enemyBox object type, and tie the 2 together using a uniqueID instance variable.

    I got so excited when I saw what containers can do. I haven't use a scene graph object yet, do you know if that may be a good option for what I'm looking to do, and if it works with families?

    It's a bummer C3 doesn't support containers with families. Both features have significant benefits and if they worked together it could make the pick code more elegant and much less error prone. I spend a lot of my time debugging issues related to object selection. Thankfully folks like you have been very helpful when I run into problems!

  • You can't use families here because they don't relate to the containers. You need to just set position for things that are in a container. You don't need to use the variables either because the containers already do the work of linking them.

    So it looks like I lose the value of families if I use containers. For example, if I every want to change the text of an enemyLabel when I click on its enemy, I can't use this because it will change the text of EVERY enemyLabel:

    Instead, I need a block like this for EVERY enemy:

    Is this correct? If so, using containers+families is a non-starter, and I'll have to go back to using families and tying enemyBox objects to enemies using the uniqueID approach (groan).

  • Gotcha - so is this what you're suggesting? It works :)

    If I have 20 enemy types I'll have to do this for each type. Not a huge deal in this case, but I can't anticipate how often I'll have to do something similar for all enemies, and I want to be clean and efficient with my code if possible. If I use the containers+families approach, is there any way I can leverage the families to simplify container-related activities? I'm assuming 'no' per your response but making sure I'm not missing something.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In my platformer, I want each enemy sprite to have an enemyBox sprite to use for movement positioning, along with an enemyLabel text. To make things easier, I was hoping to use containers.

    Since an object can't be part of more than 1 container, and I have many different enemy objects, I can't just create a generic enemyBox sprite and add it to each enemy's container. Therefore I was planning to create 3 families: enemies, enemyBoxes, and enemyLabels. Then I would make individual containers for each enemy type. I.e., zombie, zombieBox, and zombieLabel would be 1 container.

    My prototype works except for the code that positions the enemy on the enemyBox. When pressing 'z' or 'w' to create the first enemy, it places it fine. If I continue to press the same key to create the same enemy type, the new enemies are created and placed as expected. But when I press the other key to create the other enemy type, the new enemyBox is created properly but the enemy is placed on the previously created enemyBox. Pic and c3p attached.

    What am I doing wrong here?

    Question 2: is using containers + families a good approach for what I'm looking to do, or is there a better way? I originally tried using a common instance variable called uniqueID to tie the different objects together, but I ran into picking inconsistencies. The container approach seemed like a promising solution, but this issue is giving me pause.

    Thanks

    https://drive.google.com/file/d/1glQSeDO72Fvi3SsmARA-Xsh_s_3nDdIJ/view?usp=sharing

  • Example - I want to find posts containing the text "enemy box". Here's one that should come up: https://www.construct.net/en/forum/construct-2/how-do-i-18/set-sprite-position-enemy-box-101414?kws=container

    But if I put in "enemy box", with or without quotes, in the "search this forum" textfield, I get 7995 results - but don't see "enemy box" in the titles in at least the first page. If I do the same using the 'search' link in the upper right and specify 'search titles', I get 2226 results, but don't see "enemy box" in the titles (it's probably there but on who knows what results page).

    Help?

  • 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

pandabear7413's avatar

pandabear7413

Member since 9 May, 2021

None one is following pandabear7413 yet!

Trophy Case

  • 3-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • x4
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • Email Verified

Progress

10/44
How to earn trophies