Multiple Score type system

Started by jamesreg, Thu 10/05/2018 03:25:33

Previous topic - Next topic

jamesreg

I am needing to do something similar to built in score system but a little different in nature.
What I am needing to do is take a numnber 6500.00 and add to it at different points in the game.

I need it to work like this once the two numbers at the end the .00 reaches 30 I need it to reset those numbers to .00 and add one number to the 6500 set of numbers do that it is like this. 6500.30 instead of rolling over to 6500.31 it would become 6501.00. I would need this to max out at 7000.00.

Right now I had two labels one for the 6500 series of numbers and one for the .00 series of numbers but am confused on how to do the scripting.
I want to make it as easy as the score system where all I have to do is be like givescore +1 or something some simple command like that to call it up in script.

Thank you for any help anyone can give.

Cassiebsg

I'm not going to give you the code, cause I think you might be able to do that your self, so I'll just try and tell you how you can do it... or how I would do it (not necessarily the best or better way my you).

Create a function called something like AddScore() (or whatever you may like, you might probably should use points here if you want to give different scores... so lets say AddScore(Number1, Number2)...
Then in the function you add number1 and number two to the correct variable followed by the magic of if/else if/else you tell it what to do according to the value your variables now has.

Hope that helps you in the right path. (nod)
There are those who believe that life here began out there...

Snarky

You need two variables to store the numbers (well, there are ways to do it in one, but two is much easier), for example int scoreMain and int scoreFraction, and logic so that when the small one goes above 30 it gets added to the big one. However, you don't actually need two labels, just one label that displays both of them, like so:

Code: ags
lblScore.Text = String.Format("%d.%02d", scoreMain, scoreFraction);


Like Cassie says, I would make a function to add to the score (you don't mention subtracting, so I assume it can only go up), which would look something like this:

Code: ags
void AddScore(int mainPart, int fractionPart)
{
  // Increase score
  scoreMain += mainPart;
  scoreFraction += fractionPart;

  // TODO: Make scoreFraction roll over at 30 and add overflow to scoreMain
  // TODO: Max out at 7000.00

  // Display current score
  lblScore.Text = String.Format("%d.%02d", scoreMain, scoreFraction);
}


The TODOs are quite simple, but ask again if you can't figure it out.

Khris

#3
Here's the single variable way:

Code: ags
int scoreMain = 0;

void AddScore(int amount) {
  scoreMain += amount;
  lblScore.Text = String.Format("%d.%02d", 6500 + scoreMain / 31, scoreMain % 31);
}



Edit: or, if you want to use GiveScore():
Code: ags
void on_event(EventType event, int data) {
  if (event == eEventGotScore) {
    lblScore.Text = String.Format("%d.%02d", 6500 + game.score / 31, game.score % 31);
  }
}


jamesreg

Thanks for the replies guys,

I am having a minor surgery soon. It will be forcing me to be off work and not to mobile for about 6 to 8 weeks.
So I thought I would dust off my copy of AGS and revisit some unfinished projects I had played around with in the past.
I been away from AGS for quite some time never was an expert programmer to begin with but rusty on the little I did learn.
So you might see me in the forums a bit and might be some pretty basic questions but bare with me and help me get back into
the groove of things.

I'm trying to go back and revisit projects I did before and learn from the mistakes I made or go back and fix shortcuts I took
when I did not understand the more professional way to do some things and clean things up and improve my skills some.

I'll test out all your ideas this weekend thank you for the replies.

Cassiebsg

Good luck with the surgery and fast recovery!

6 to 8 weeks? Sounds like perfect timing to so a game for MAGS... ;) A brand fresh game will brush up your coding much faster than trying to figure out what you did before and how to improve it. ;)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk