Why doesn't this line of code work for spawning enemies?

0 favourites
  • 6 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • See the picture below.

    The top line works every time if it compares less than or "<" 200, but the bottom event where it wants to spawn something as greater than 200 will never work. It's a large layout with plenty of tiles. I don't understand why the second one won't work. Am I not understanding the logic behind this event?

    Again, the top event works every time even if I put the door in there too. The bottom event will not spawn anything.

    I wanted to make it ">" so it would spawn enemies and doors away from where the heroes spawn rather than right on top of them. Is this condition not doing what I think it is?

    In fact, even if I make the second event say " > 1" it still won't work, so obviously it's not an issue with map size.

  • one thing that sticks out is Trigger Once should be after the condition.

    Trigger once while true

    Turn an ordinary event (which is tested every tick) in to a trigger. For example, if an event plays a sound when lives equals 0, normally this event runs every tick. This plays about 60 sounds a second and would sound pretty bad. Adding Trigger once while true after the other conditions makes the event run just once when it first becomes true. This makes the previous example only play a sound once the first time your lives reaches 0. *It must be the last condition in an event.

    what exactly is "ground"?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jobel Ground is a floor tile that is created during the map generation. The other tiles are wall tiles.

    So basically, I just want to spawn something on a ground tile at random. Like I said, it will work if I set it to less than 200, but greater than 200 will never work. There is plenty of room and plenty of tiles. I just don't understand it.

    I tried moving trigger once to after the condition, but it didn't seem to matter. I may have already tried that. I don't really remember. Since it worked like that for the less than 200 event, I thought it would work for both.

    The goal with this was just to keep stuff from spawning too close to the player.

  • so you know for a fact there are ground tiles that are over 200 pixels away from the player at the time this code executes?

    is heroes just 1 object?

    I think this is going to pick more than one tile, Pick by eval picks all relevant objects. Just having the "Trigger Once" in there isn't going to make it only pick 1 tile. But obviously your first condition is working so that doesn't explain the second not working.

    you aren't using any parallax are you? I know that messes up coordinate stuff.

  • jobel Well, I think I got it sorted. I rewrote the code a bit to this:

    I used two separate conditions. Rather than pick by evaluate, I used pick random and system compare two values. I had to put the trigger once event first or it would go crazy and make tons of them. I was also able to increase the number higher than 200.

    By the way, heroes was a family with 3 people in it. Anyway, I think that wraps this up for now. I need to do more testing and see if this is what I want vs another method to spawn things.

    Honestly, I just don't understand how the logic works sometimes...

  • the way you reference heroes is a little weird.. you aren't looping through all your heroes, it seems you are only referencing a random one? I think you need a For Each heroes event in there..

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