Hi there

I am currently creating a game, where you drop items in certain areas, at the moment i want the player to drop only a max of 6 bombs, but one at a time.

Currently my programignores the list count max of 6 and just keeps drawing until i let go of the A button.

any thourghts on how to fix this bug??

LNC

Dani AI

Generated

The behavior you describe (keeps creating bombs while A is held) is almost always an input-sampling issue rather than a List bug. is dropping items repeatedly because the game sees the button as "down" every Update frame. The two reliable fixes are: 1) only act on the button edge (press event) instead of continuous down, and 2) enforce the max check before adding and remove bombs from the list when they expire so the count stays accurate. ’s inventory/count idea is useful if you treat bombs as a limited resource rather than world objects — combine that with edge detection.

Example edge-detection pattern (XNA / C#):

private KeyboardState prevKb;
private const int MaxBombs = 6;
private List<Bomb> bombs = new List<Bomb>();

public override void Update(GameTime gameTime)
{
    var kb = Keyboard.GetState();

    // fire only when key transitions from Up -> Down
    if (kb.IsKeyDown(Keys.A) && prevKb.IsKeyUp(Keys.A))
    {
        if (bombs.Count < MaxBombs)
            bombs.Add(new Bomb(player.Position));
    }

    prevKb = kb;

    // update bombs and remove expired ones
    for (int i = bombs.Count - 1; i >= 0; i--)
    {
        bombs[i].Update(gameTime);
        if (bombs[i].IsExpired)
            bombs.RemoveAt(i);
    }
}

If you want a time-based limit instead of strict single-press gating, add a cooldown timer and decrement it with gameTime.ElapsedGameTime. Additional troubleshooting: make sure input logic runs in Update (not Draw), do not add items inside a loop that iterates the same list, and avoid confusing List.Capacity with List.Count. If the problem persists, add an OutputDebugString/Console.WriteLine to log when the add path runs so you can see why the check is being bypassed.

Greetings, well i'm curently developing a FF type game, the only dropping action there is is the mob loot, but it might help you, what i have is:
-Create a list and ammount of items variables;
-Check if item already exists in invetory, if it does, Raise the ammount;

i think that with this you can do the other way around, instead of raising the ammount, decrease it. I hpe this helps you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.