How to add a score

Discussion in 'Programming' started by nessabby1, Jul 25, 2016.

Tags:
  1. nessabby1

    nessabby1 Guest

    How do i display a score for how long the player stays in the game without colliding into the obstacles. The player itself doesnt move, just the ground n obstacles move towards makes it seem as if its moving. I want the score to be like the distance just like most of the runner 2d games.
     
  2. Jobo

    Jobo Member GMC Elder

    Joined:
    Apr 19, 2016
    Posts:
    311
    Hi!

    "Score" is just a label you've chosen to use to identify a value. This is what a variable is. It's a label that refers to a specific value. So first thing you want to do is create that variable in your player's Create event:
    Code:
    score = 0; // assign the value 0 to score
    
    Because you want this value to keep incrementing over time, we can use the Step event. In the Step event, add a number to the value based on how fast you want the score to increase. Keep in mind that the Step event is executed once per frame, so if your room speed is 30 your Step event will execute 30 times a second. If you increase score by 1 each step, you will thus gain 30 score in 1 second.
    Code:
    score += 1; // add the value 1 to score
    // can also be written as 'score = score + 1'
    
    Next you want to display the player's score on the screen. To the Draw event!
    Code:
    draw_text(10, 10, score); // draw the score variable at 10,10 (10 pixels from the left edge of the window and 10 pixels from the top edge of the window)
    
     
  3. Cmi

    Cmi Guest

    Make a global variable
     
  4. nessabby1

    nessabby1 Guest

    Okay thanks,but. now how do I get the score to stop when the player collides into the object?
     
  5. TatorToot

    TatorToot Member

    Joined:
    Sep 29, 2017
    Posts:
    1
    So, I presume you have code in the objects already and that everything is working as far as the ground and obstacles moving. If you chose to try this method, just add this in to your code or think of a way to mix it in with some more Try this:

    In Create Event(Player):
    Code:
    {
         scoring = true;   //Sets "scoring" variable to true
    }
    
    In Step Event(Player):
    Code:
    {
         if (scoring = true) {   // This checks to see if "scoring" is true. If it is, it'll continuously add to the score score
              score += 1;   // You can replace 1 with whatever number you want depending on how fast you want the score to go up
         }else{  // This says that if scoring is false, the player dies, because the only way it can be false is if it hits an obstacle
              instance_destroy();  // Destroys the player object
         }
    }
    

    In Collision Event With All The Obstacles(Player):
    Code:
    {
    
         scoring = false;
    }



    Once again, just add this in to your current code or find a way to mix it in with the rest to make it look cleaner. This should work, but let me know if it doesn't. And also, you're probably not even working on this game anymore or you got it fixed already, being that it was more than a year ago when you originally posted, but in case you were still wondering, here's a solution.
     
  6. Scott Boardwine

    Scott Boardwine Member

    Joined:
    Oct 30, 2017
    Posts:
    10
    I would like to know how to set up a score so when I kill my enemy I get 10 points in my score. I tried doing this many of ways but can't seem to get it working. My enemy takes multiple shots before dying and I'm not sure where to put the code or using DandD. Can someone be so kind to show me where I need to put the set score code? i provided images to take a look at my enemy step and controller step. Btw my score is drawn on screen so im good there
     

    Attached Files:

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice