variable not work properly

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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

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

  • 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?

  • [quote:wghz9loo] Your saying they keep spawning when they shouldn't be?

    Yeah, they usually spawn more than one group.

    [quote:wghz9loo]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

    I use that based on tutorial and people's post on forum

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

    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.

  • 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

  • can't send PM, need 500 rep

  • enemy on destroy add-1? shouldnt it be subtract 1?

  • 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.

    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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I haven't used this yet because I pretty much put everything in one sheet, but I make sure that only a small part of it runs at any given time. It does seem like a very useful feature though. It's description says it's as if you copy pasted the script from one sheet into another so I don't think it will give you unexpected problems.

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