Announcement

Collapse
No announcement yet.

Setting a score only once

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Setting a score only once

    Hey there,
    I'm new to UE4 and still trying to get my head around programming procedures. This may be a problem that occured many times before, but I can't think of a way to put my problem in a different context and thus can't find solutions yet. Note that my project is yet completely on paper in a hope to spare me editing time in the end.
    Anyway here is what I aim at:
    I want to create a basic Tower Defense in which you get Upgradepoints depending on how you performed in the current level. By finishing it the player shall receive Upgradepoints once in "increasing" steps. For example: Finishing it with the main hub at 100% health gives 3 points (which would be the maximum of points gained in normal play mode), finishing it with the main hub at 70% would give 2 points and any finish below that would give 1 point. These points should add to a total Upgradepoint counter consisting of all points gathered throughout the levels, preferably in a GameInstanceBP, which than can be used by different BPs to buy Upgrades for Towers etc that matter in later playthroughs of levels. In addition to that I would like to have two extra Play modes per level which each separately should give 1 point extra on completion that add to the maximum of 3 points in normal mode, making it a total maximum of 5 points.
    Now I can't get a grasp on how to approach this. I would like to set these by a "cast to GameInstanceBP" in an Integer, but I fear that upon replaying the same level these points will exceed the possible maximum points or, -if a maximum number is set-, this number could be reached by completing the level multiple times without actually reaching the best score (i.e. three times 1 point=maximum points of 3). Then again I would not want it to be a ladder upon which the player would need to play the level three times to reach the best possible score, but to be able to reach 3 points on default and not be able to deteriorate their score once it reached a milestone. With the additional play modes my brain really starts to melt, making the maximum number of points as a branch condition nearly impossible in my mind and leading to an uncountable amount of boolean variables, which I would like to avoid (if there are better solutions).
    This may seem very trivial since I do not know all possible nodes yet and I guess I used more words to desrcibe this problem than needed, but I wanted to make my point clear (and hopefully did).
    With best regards, Jonny.

    #2
    First and most important question: Is this a multiplayer game?

    Comment


      #3
      No, not from my intentions. There is no high score counter either, it's more of a "Get five stars per level and invest them in Upgrades such as 'more Gold to start with' or 'higher range per tower'".

      Comment


        #4
        Ok, all of the following values will be in your GameInstance: I would make an array of ints, each index representing one level. In your level blueprint you can calculate how many points the player earned at the end of the game and then check with your array, if that number is bigger than what is already in the array. If true, write new highscore to array and update your upgrade points by adding the difference between said values to them. Your 'cast to' idea is what i suggest as well, but dont manually set the vaules, make functions that handle stuff for you, so you dont have to copy the nodes into all levels. That covers the part how to calculate and store the values at runtime and will prevent exceeding the cap you chose.

        But since the game will inevitably be closed, you will need to store the highscores in a SaveGame file, which will be saved everytime a level is finished and loaded before the level begins. If you have any questions regarding this, let me know.

        Comment


          #5
          Alright, first of all thank you very much! The "adding the difference" part was what I was not seeing, but hoping to get as a solution. I never worked with arrays this way nor heard of this certain use, especially with different indexes to access individually.

          The SaveGame part will be something I'll aim at once I know what content needs to be safed.
          Thanks again!

          Comment

          Working...
          X