How do I make a coin, hitpoints, and flowerpoints counter?

0 favourites
  • 12 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • *If it helps I have a spritefont that I'm using to help with hitpoints coins and flowerpoints*

    So here's what I need help with, how do I set up the hitpoints where it's in this format (n stands for number): nn/nn? The first 2 n's are how many hitpoints the character has currently and the last 2 n's are how many hitpoints the player can have up to? Same format applies to flowerpoints.

    And then I need to have a way to count all the coins the player collects

    Can anyone help me?!

  • The best way to do this would be to store the maximum and current hitpoints in an (instance) variable and use the variables to display it.

    Set the text to "[currentHP] & "/" & [maxHP]"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In short, your answer is Variables. you can use Instance or global variables, though instance variables are geared more towards hoards of enemies. if its player vs player, you can get away with using global variables.

    once you create the global or instance (Numerical) variable , your code would look something like :

    Player- On hit - subtract X from HealthVariable.

    you can use the same logic in reverse.

    player-on collision w item - add X to HealthVariable

    To kill player when life is at 0 or below (in case player is at 1 health and is hit twice at once)

    If HealthVariable = equal or less than 0, player = destroy

    Similarly, If They Pick Up Health, Instead of Stacking 999999/100 health, You can cut it off at a maximum.

    If HealthVariable = Greater than MaxHealth, Set HealthVariable to MaxHealth

    The same with 'FlowerPoints'. Create A Variable named Flowerpoints.

    Player - On Collision - Add X To Flowerpoints.

    Every Tick - Set FPText To - "Flowerpoints : "&Flowerpoints

    - Set HPText To -"Health : "&HealthVariable" / "&MaxHealth

    You can then create pickups that allow for More than Max Health.

  • *special pickups. if you havent figured it out yet, you can also create a variable, an call it "Coins". player-on collision-add 1 to Coins. every tick - set cointext to -"Coins : "&Coins

  • Ok, so I did everything you said, or tried to do everything you said and so far it's not working. How do I attach the .capx file to here?

  • Share on dropbox or google drive!


    Here it is....I hope this is the correct file.

  • That's a broken link and looks like a pdf file which won't be the correct capx file.

  • Try it now.

  • If you check out my edit on event 13, I fixed the health. ... .capx?dl=0

    When referencing a variable you need to do object.variable. In quotations "" that is just text.

  • more thing, and I'm sorry I'm asking you so many questions, can you explain what you just did so I can do that for other things?

  • Well if I was to say do it a certain way, I would say scrap that local variable on font object. When you change to a new layout later on it will cause problems. The best way to do player health is to use a global variable and reference it. The variable is a value that is always there and changing. For the display of it, you are just referencing that value, so in this case the health is HPFont.currenthealth / HPFont.maxhealth. You should use a global variable so you dont need to reference an object, so playerHealth / 5 will do! It's just about getting familiar with the C2 basics. In terms of the actual text event, you separate bits out with an & symbol.

    To break it down even further so you have an understanding and can then go on to do it with the flower points. You store values such as health and items collected as a variable. They are always there in the background and changing, you can add and subtract from them. You can use a text object to display text, but also to display these variable values that are constantly changing during gameplay. Using SetText you can set the text to show a variable such as health. Every Tick is used to update the values constantly during the gameplay.

    Edit: if you check the link again, I've done this. I changed it to global health and coins for you.

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