Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using in game store Credits?

Discussion in 'Scripting' started by tredpro, Nov 23, 2014.

  1. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    So i have it set up where our database stores the amount of credits that a user may have purchased from us.

    what i am needing help with is:

    1) I need the user to be able use the credits to make future purchases

    2) when they make a purchase i need them to be able to enter an item name and the amount they want to spend towards that

    3) i need it to automatically update the credits the user has

    4) and i update a database that will list all the items requested. we need this database to work like this: when a purchase is made it checks to see if that item name is already listed. if it is, it will add the amount the user just paid to the already listed. if it isn't already listed then it will add the item and the amount.

    I have been trying to figure this out for quite some time now. please let me know if anyone can help me with this.
     
  2. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    You may be interested in the Soomla framework - http://soom.la/

    If you're needing to update a database on your own servers, you can use the callbacks within Soomla to make calls to whatever database API you have instated.
     
  3. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    I don't know if that is what i am looking for.

    i believe this is all i need help with but i can't figure it out.

    im needing to write a code that allows the user to use the credits that they purchased. they pick the amount they want to use and the rest they keep and whatever they spend goes away.
     
  4. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    If you've already written the code needed for the purchasing of credits, than it should be trivial to create one for pulling a desired amount from said currency?
     
  5. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
  6. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    From skimming over the thread you posted, the package appears to be using a PHP and MySQL backend. So you would need to make a query to check the available currency.

    Code (csharp):
    1.  
    2. SELECT credits FROM users WHERE User='UserName';
    3.  
    Then after you have received that information you would need a check against that value and the price of the item for purchase. If everything checks out, then you would need to update the SQL table to reflect the new value of credits.

    Code (csharp):
    1.  
    2. UPDATE credits SET credits=1234 WHERE User='UserName';
    3.  
    I don't have the package that you are currently using, and as such am unaware of the table and row names of the database, so the above is purely to give you a very general idea of what you would need to do for updating the database. I haven't dealt with critical databases in quite a long time, so I would highly advise seeking further knowledge on how to query and process in an efficient and secure way.

    Also if you are planning to release to the App Store, you would not be able to use PayPal and would have to go through Apple's IAP system for purchasing of the credits.
     
  7. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    where you put 1234 is that the cost of the item?

    or are you making the credits 1234?
     
  8. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    That value would be the calculated remaining credits after the purchase has been initiated. But I am fearing we are getting quite ahead of ourselves here. Why don't you post the code that you have written thus far and we can start with that.
     
  9. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
  10. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    I apologize, but I do not have the time to personally take on writing this script for you - nor would that benefit you as an aspiring programmer. My intent in having you post the code which you have written for processing your credits so far would be to allow the community to once-over the code and provide any feedback on glaring errors that were spotted.

    If you are unable to write the code needed for deducting a value from a database it may be a good time for you to take a step back, read a few articles, and maybe tackle some smaller tasks in your project while working up towards building an IAP system.
     
  11. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    well that is what i am trying to do. but im not sure what to search for
     
  12. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    If you are intending on sticking with the asset you are currently using, you should ask yourself how well you grasp the concepts of PHP and how to work through it with MySQL and build your understanding from there.

    The chances of you finding a detailed article on exactly what you are hoping to accomplish are slim to none, and even if you were to find one, it would be beneficial to have an understanding of the code, not just understand how to call the provided methods.
     
    angrypenguin and Stoven like this.
  13. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    well i learn hands on. that is why i am trying to figure this out. i haven't asked anyone to give me the answer but help me figure out what i am looking for.
     
  14. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    Let's be short then.
    1. Verify local database is synchronized with server database, to circumvent a margin of users attempting to cheat.
    2. Query database tables for rows containing credits based on user identifier and costs of individual items to be purchased.
    3. Don't forget to index queries for performance.
    4. Compare cost of transaction to the currently held credits.
    5. Update database table for row containing credits and owned items based on user identifier.
    6. Grant user access within local database to newly purchased items if callback from server update was successful.
     
  15. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    (looks like question has evolved from a general one into one asking for scripting help)