Jump to content

Coding the currency


Recommended Posts

Hello everyone!

I have began general css and html work on a little pet project, a new one, and am making some progress. Super excited, but theres a few threads here and there that I keep getting snagged on. The biggest one at the moment is game currency.
Going off one of the tutorials here, I designed the best way is to start with a login system and the game currency. Following that logically next would be a store, items, inventory, and then finally the pets themselves which are going to be the biggest obstacle. 
I have decided to use php and mysql, and have been slowly learning all about them.  I have already researched login systems, and that should be easier to do as it has a lot of info online. However, currency systems in browser games are not as easy to research, so Im having a bit of an issue with them.
Could anyone give me a little advice on it? And some links with resources? 
Thank you
Edited by April
Link to comment
Share on other sites

Hi April,

Once you get your login system working and retrieving the user data (such as username) from the database, it should then be really easy to retrieve other information such as the currency. I'd suggestion creating your create account/login page first, because this will force you to implement your database connection which would be the backbone of all database communications.

To start with that, your best bet to is to check out @judda's pdo wrapper here. It does alot of the legwork for you, especially with things like security and preventing SQL injection.


  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@April You can consider the bank/current to be a lot like the user login system that you already built (most features end up following a similar pattern).

  1. Create a table (or just a field on the user's table) that will contain their current currency amount
  2. Retrieve the user's current amount of currency from the database
  3. Then whenever you are able to play with it / modify the value since it's been retrieved

You should aim to have all interactions (removing/adding money) in their own helper functions so that you aren't removing it inconsistently, which will also allow you to add functionality like a transaction log could be easy to implement.

I know I'm a little vague here, but let me know how we can help!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...