
-----------------------------------
programmer_needs_help
Thu Jun 08, 2017 4:55 pm

max id error with sprites... CONTINUED
-----------------------------------
So i'm making a sword fighting game in turing and after repeated use of the attack button an error occurs and the game crashes. It's a max ID error i think becuase each time the player attacks the sprite image is replaced. If you have a suggestion can you please write the code? I'm kind of new to sprites and stuff. Thank You Smile 

The following is the code snippet: 

% Sword Attack 
elsif arrowInput (' ') and playerYValue  0 and playerXValue > enemyOneXValue then
            enemyOneXValue := enemyOneXValue + 2
            Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true)
        elsif enemyOnePlayerDistance < 15 then
            randint (attackChance, 1, 4)
            if attackChance = 1 then
                Sprite.ChangePic (enemyOneSprite, enemyOneSword)
                Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true)
                View.Update

                if a = 0 then
                    numLives := numLives - 1
                    if numLives = 2 then
                        Sprite.Hide (lifeHeartsSprite)
                        lifeHearts := Pic.FileNew ("lifeHeartsTwo.bmp")
                        lifeHearts := Pic.Scale (lifeHearts, 80, 40)
                        Sprite.ChangePic (lifeHeartsSprite, lifeHearts)
                        Sprite.Show (lifeHeartsSprite)
                        Sprite.SetPosition (lifeHeartsSprite, CENTREX - 370, CENTREY + 250, true)
                    elsif numLives = 1 then
                        Sprite.Hide (lifeHeartsSprite)
                        lifeHearts := Pic.FileNew ("lifeHeartsOne.bmp")
                        lifeHearts := Pic.Scale (lifeHearts, 40, 40)
                        Sprite.ChangePic (lifeHeartsSprite, lifeHearts)
                        Sprite.Show (lifeHeartsSprite)
                        Sprite.SetPosition (lifeHeartsSprite, CENTREX - 370, CENTREY + 250, true)
                    end if
                    a := 1
                end if
                exit when numLives = 0
            end if
        end if
        delay (7)
    end loop

    Sprite.Hide (enemyOneSprite)
    Sprite.Hide (playerSprite)
    gameOver := Pic.FileNew ("gameOver.bmp")
    gameOver := Pic.Scale (gameOver, 930, 605)
    Pic.Draw (gameOver, 0, 0, picMerge)
    loop
        Sprite.Hide (lifeHeartsSprite)
        Sprite.Hide (enemyOneSprite)
        Sprite.Hide (playerSprite)
        Sprite.Hide (fireballSprite)
    end loop
end enemyOneAttack


fork enemyOneAttack
fork fireballMoving
fork playerMovement


however, when I press and hold the attack button (space bar) the enemy AI movements slow down

-----------------------------------
programmer_needs_help
Thu Jun 08, 2017 8:58 pm

RE:max id error with sprites... CONTINUED
-----------------------------------
sorry for the late message!
