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

Get help using Construct 2

Post » Wed Jul 16, 2014 2:18 am

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?

Image

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.
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Post » Wed Jul 16, 2014 4:50 am

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"?
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Jul 16, 2014 5:05 am

@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.
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Post » Wed Jul 16, 2014 5:21 am

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.
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Jul 16, 2014 6:09 am

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

Image

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...
B
79
S
30
G
35
Posts: 340
Reputation: 22,996

Post » Wed Jul 16, 2014 3:37 pm

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..
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 33 guests