variable not work properly

Get help using Construct 2

Post » Wed Nov 04, 2015 2:22 pm

Hi, i'm beginners on construct 2
So I just try this to make enemies spawn based on the "spawnon" and "enemy"variable

->system spawnon = 0 | system set pattern to choose (0, 1, 2)
->system trigger once |
-->system pattern = 0 | "enemy spawn"
-->system pattern = 1 | "other kind enemy spawn"
-->system pattern = 1 | "another kind enemy spawn"

then

->Enemy on created | Add 1 to enemy

->Enemy on destroy |Add -1 to enemy

->system enemy > 0 | set spawnon to 1

->system enemy = 0 | set spawnon to 0

but after all first wave enemies destroy, the next wave usually spawn more enemies than it should be (like pattern 1 and 2 spawn together, or pattern 0 spawn double), and I can't find where is the problem.
If anyone can help i would be grateful :)

*english is not my native language
B
3
Posts: 5
Reputation: 185

Post » Wed Nov 04, 2015 4:35 pm

Your saying they keep spawning when they shouldn't be?
Eat ALL THE BACON!
B
47
S
17
G
3
Posts: 290
Reputation: 5,070

Post » Wed Nov 04, 2015 5:10 pm

Could you take a screenshot of your script and post it here? Someone could find the problem faster that way.

For now I understand that you are trying to spawn 1 random enemy at a time and after the first one is destroyed you get 2 random enemies at a time but I can't see the problem in your script. Is any of the variables a Local Variable?
B
7
S
1
Posts: 29
Reputation: 483

Post » Thu Nov 05, 2015 4:29 am

Your saying they keep spawning when they shouldn't be?

Yeah, they usually spawn more than one group.

Could you take a screenshot of your script and post it here? Someone could find the problem faster that way.

For now I understand that you are trying to spawn 1 random enemy at a time and after the first one is destroyed you get 2 random enemies at a time but I can't see the problem in your script. Is any of the variables a Local Variable?


Maybe the pict will explain
Image
Image
I use that based on tutorial and people's post on forum
B
3
Posts: 5
Reputation: 185

Post » Sat Nov 07, 2015 10:33 pm

I tried to copy your code and see what would happen.

Image

Aside from a few variations and a couple of additions to make things clearer, the code is the same. Instead of tanks coming from you right I have ships coming down from the top in a vertical layout. Also their spawn positions are not random like yours.

The code worked exactly as intended. The original enemy sprite has a blue tint so I let the ships spawned on pattern = 0 with the original coloring but gave ships spawned on pattern = 1 a red tint and the ones spawned on pattern = 2 a green tint to clearly differentiate them. They never mixed up. There were either blue enemies, red enemies or green enemies on the screen. For pattern 0 and 1 it spawns 4 ships in a wave and for pattern 2 there are 8 ships. Everything seems to work fine so your problem might be in some other detail.

I would like to give you the .capx file but I can't post links until I have 500 reputation. If you are interested, message me with an email address.
B
7
S
1
Posts: 29
Reputation: 483

Post » Sun Nov 08, 2015 4:13 pm

@trashgg thank you for testing it.

maybe because I use the "include event sheet" feature, and it's make the variable didn't stop on time (I use debug mode, the 'pattern' variable keep changing for a split second after the enemy spawn). I think I should test it again or find another way to make a similar spawn system, 'cause I can't find the problem too.

I'll message you immediately, thank you for your help :)
B
3
Posts: 5
Reputation: 185

Post » Sun Nov 08, 2015 7:32 pm

can't send PM, need 500 rep
B
3
Posts: 5
Reputation: 185

Post » Sun Nov 08, 2015 8:14 pm

enemy on destroy add-1? shouldnt it be subtract 1?
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Mon Nov 09, 2015 12:53 pm

bangnew wrote:can't send PM, need 500 rep


I just noticed the same thing. Sucks to be newbies. Send me an email at trashgg at yahoo dot com and I'll reply with the capx attached.

PulvererPeter wrote:enemy on destroy add-1? shouldnt it be subtract 1?


It works both ways, I checked. But thanks to your observation I just realized something. If you kill the first enemy in pattern 1 in less than 1.5 seconds, before the second one spawns, then enemy = 0 and the wave resets and chooses a new pattern. That might be what's happening in bangnew's game. Maybe his enemies get killed much faster than in my example.

I tried a different approach. Set the number of enemies that will be spawned at the beginning of each pattern's list of actions
pattern = 0 => set enemy to 4
spawn first enemy
spawn second enemy
spawn third enemy
spawn fourth enemy

and so on. For pattern = 2 set enemy to 8 of course. Also, you need to remove "enemy - on created => add +1 to enemy" since the number is already set. This will solve the problem but you should note that the enemy variable no longer displays the number of enemies in the layout but the number of enemies that will be spawned for the current wave.
B
7
S
1
Posts: 29
Reputation: 483

Post » Mon Nov 09, 2015 4:56 pm

@PulvererPeter I didn't see the "substract" functions, thank you for noticing :)

@trashgg yep I notice that one too, so I try to add another variable that tell if a pattern spawn already done or not. It change on first when the pattern are chosen and after last enemy are spawn.

One question, are "include event sheet" are perfectly fine if I include more than one sheet or it can 'cause glitch on the system? because this feature is very helpful to make multiple layout with one system.
B
3
Posts: 5
Reputation: 185

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests