[SOLVED]How to make a currency system based off of in game score?

K

KlawSin

Guest
So I want to make an in game store where the player can buy different sprites to play as with their currency. I want the currency to be made based off of their score they get within the game.

To give you an idea of what the game is, it is a quick mini-game that usually lasts between 10-20 seconds so it is very quick. I want their score to add to their currency (which would need to save in between opening and closing the app), and then be able to use this currency to purchase different skins (sprites) for their character.

I have the score system working fine and even a local highscore system. I just cannot for the life of me figure out how to implement this currency system. Any help is appreciated.

Thanks.
 

NightFrost

Member
You'd need to store the currency counter in an external file. Load it when the app starts, add to it after each game and save back to file, substract from it after every purchase and save back to file. I'm not familiar with android side of things so I don't know if simply using ini files for storage would work (ini_open, ini_write_real, etc).
 
K

KlawSin

Guest
You'd need to store the currency counter in an external file. Load it when the app starts, add to it after each game and save back to file, substract from it after every purchase and save back to file. I'm not familiar with android side of things so I don't know if simply using ini files for storage would work (ini_open, ini_write_real, etc).
I have been using ini with the local highscores and it works the same on android from the testing at least.
I am not exactly a great coder so I am not exactly sure how to go about this system. (Plus I'm fairly new to game maker as well.)
So would the code look something like:
ini_open("currency.ini");
ini_write_real("Currency","total", +=score);
currency = ini_read_real("Currency","total", 0);
ini_close();
I'm not really sure how to add things into these ini files because, like I said, I'm really not great at coding. Pretty much all of my game has been done through the drag and drop system except for the highscore saving.
Thanks
 
K

KlawSin

Guest
Just a follow up, I got the currency system working. Thanks for the help.
I ended up attaching this code to the play button so it would create the variable and update each time they started a new game.

ini_open("currency.ini");
global.currency = ini_read_real("Currency","total", 0);
ini_write_real("Currency","total",global.currency + score);
global.currency = ini_read_real("Currency","total", 0);
ini_close();
I had to repeat line 2 again at line 4 because if it was the first time playing they would need to create the variable for currency or else it would crash. And it is repeated at 4 because every time they clicked play the currency wouldn't be updated correctly, it would always be a game behind. But this all seems to work now.
 

FrostyCat

Member
I had to repeat line 2 again at line 4 because if it was the first time playing they would need to create the variable for currency or else it would crash. And it is repeated at 4 because every time they clicked play the currency wouldn't be updated correctly, it would always be a game behind.
Why would you need to? You could have just updated global.currency before writing back, not after.
Code:
ini_open("currency.ini");
global.currency = ini_read_real("Currency", "total", 0)+score;
ini_write_real("Currency", "total", global.currency);
ini_close();
 
K

KlawSin

Guest
Why would you need to? You could have just updated global.currency before writing back, not after.
Hey thanks, I didn't know you could do that. I'm still pretty new to this programming stuff.
 
Top