Right, let's get doing this!
I'll try and explain my thought process, since I may get my theory wrong, and in which case, you can try and see where I went wrong in... trying to figure out when your code went wrong.
...man, this might get complicated
So the problem is that two arrows are being created sometimes. This is presumably coming from the step event of obj_green, because as far as I can tell, that's the only time you ever create objBullet.
What I would do myself, right off the bat, is right next to each bit of the code that creates a bullet, make it cause a little pop up.
For example, when you create the bullets of charge level 4, a bit of your code looks like this:
charge_level = 4;
bullet = instance_create(x,y,obj_bullet);
with (bullet){charge_level = 4;}
I would just add a simple line, make it like this:
charge_level = 4;
bullet = instance_create(x,y,obj_bullet);
with (bullet){charge_level = 4;}
show_message("The bullet has charge level 4.");
Do that for the other two bits in the code where it creates bullets. Who knows, it may turn out that you're creating a bullet of charge level 4 and a bullet of charge level 3 in the same step. This would help you find out a bit more about where the error is.
Then again, given all the else ifs, that doesn't look like it'll be the problem...
Again, we look at the three different places that a bullet gets created. Based purely off your if statements ("if shot_true = 1", "else if shot_ready = 1" and "else if instance_exists(obj_shot_charge)"), ignoring every other bit of code, try and track down what might cause this problem.
If "key_shoot = 0" is true for two steps in a row, it'll go through all the if statements twice in a row. This is very likely (as most players won't immediately start charging an arrow the moment they've loosed one). This means that any of the following could cause double arrows:
- shot_true == 1 and shot_ready == 1
- shot_true == 1 and (instance_exists(obj_shot_charge) and obj_shot_charge.charge_level > 0)
- shot_ready == 1 and (instance_exists(obj_shot_charge) and obj_shot_charge.charge_level > 0)
- A single one of your ifs being true, and not made false by next step
With the method I mentioned before of putting a show_message in next to each of your instance_create(x,y,obj_bullet) lines, you should hopefully be able to track down which of the above possibilities is causing the problem. Then just... make them false... Err...
I'm having a lot of trouble explaining this, so I'll just write up some psudo code to make my thoughts clearer.
So here's a little series of things which loosely mimics what you have:
if bullet_ready = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 3;}
bullet_ready = 0;
}
else if bullet_true = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 2;}
bullet_true = 0;
}
else if bullet_done = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 0;}
bullet_done = 0;
}
The first thing I'm saying you should do is add a bunch of show_messages, make it more like this:
if bullet_ready = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 3;}
bullet_ready = 0;
show_message("Bullet created, charge 3");
}
else if bullet_true = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 2;}
bullet_true = 0;
show_message("Bullet created, charge 2");
}
else if bullet_done = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 0;}
bullet_done = 0;
show_message("Bullet created, charge 0");
}
Now run your game. Run it until two bullets are being created. When it happens, let's say you get two messages.
"Bullet created, charge 3"
"Bullet created, charge 0"
This means that somehow, both bullet_ready = 1 and bullet_done = 1 are returning true.
One easy fix that may or may not work would just be to add "bullet_done = 0" inside the first if, like so:
if bullet_ready = 1
{
with (instance_create(x,y,obj_bullet)) {charge = 3;}
bullet_ready = 0;
bullet_done = 0;
show_message("Bullet created, charge 3");
}
If that works, yipee! It might also not work. If that's the case, move on to the next thing.
If the solution I just gave didn't work, or if your messages are both the same, like:
"Bullet created, charge 2"
"Bullet created, charge 2"
Then it gets nastier. It means that somewhere else in your code, something is setting bullet_true to be 1 again, when it shouldn't. That's harder to find, you'll have to trawl through it all.
I can't actually see the problem myself in the code, it's really hard to understand what happens just from the game. So I'd recommend trying to fix the problem yourself (that's always better than getting someone else to do it, because then you can learn more about problem fixing
). If you can't find it, you seem happy to share the source, so you could do that, and I could try and find the problem. But honestly, that should always be a last resort. I'm sure you can find and fix the problem yourself