Skip to content

Instantly share code, notes, and snippets.

@Sumolari
Created April 18, 2016 16:11
Show Gist options
  • Save Sumolari/878eb47d383290a20aead22f59a1e6ae to your computer and use it in GitHub Desktop.
Save Sumolari/878eb47d383290a20aead22f59a1e6ae to your computer and use it in GitHub Desktop.
Checks if player has enough money to buy an item, and buys it if possible
#include "MawKit/KVDatabase.hpp"
bool buyIfPossible( long long price )
{
constexpr const char *moneyKey = "money";
if ( MK::KVDatabase::getLongValueForKey( moneyKey ) > price ) {
MK::KVDatabase::decreaseLongValueForKey( moneyKey, price );
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment