Page 1 of 1

need help with code for a money system

Posted: Thu Aug 13, 2015 2:35 am
by Lucky1443
I need some help adding to the money system code, where if you don't have enough money you cant buy something, I can't really think of a way too do that.

Re: need help with code for a money system

Posted: Thu Aug 13, 2015 2:48 am
by chocojax
You could do something simple like:

Code: Select all

# assuming money is a global var
def check_money( item_cost ):
    if money < item_cost:
        return False # cannot buy
    return True # can buy, probably add code to add/have the item

Re: need help with code for a money system

Posted: Thu Aug 13, 2015 2:49 am
by trooper6
I you don't know much about Python, I'd recommend you take the free course over at codeacademy.com
I say this because a money system is mostly just some basic python.
If is an if statement.

Code: Select all

if money < cost:
    "You don't have enough money."
else:
    "You have enough money."
You might want to look over this thread I posted in as well. http://lemmasoft.renai.us/forums/viewto ... +inventory

But to the code academy python course.

Re: need help with code for a money system

Posted: Thu Aug 13, 2015 2:14 pm
by Lucky1443
trooper6 wrote:I you don't know much about Python, I'd recommend you take the free course over at codeacademy.com
I say this because a money system is mostly just some basic python.
If is an if statement.

Code: Select all

if money < cost:
    "You don't have enough money."
else:
    "You have enough money."
You might want to look over this thread I posted in as well. http://lemmasoft.renai.us/forums/viewto ... +inventory

But to the code academy python course.
For my game how would I change the code, because I can't keep track of what choices people pick that may give them more money, so that if the amount of money they have is more than the cost they can buy it, and if they have to little they cant? sorry If i sound confusing

Re: need help with code for a money system

Posted: Thu Aug 13, 2015 2:37 pm
by trooper6
Lucky1443 wrote: For my game how would I change the code, because I can't keep track of what choices people pick that may give them more money, so that if the amount of money they have is more than the cost they can buy it, and if they have to little they cant? sorry If i sound confusing
You do not sound like you know anything about how to use basic variables. But you also want to do complicated things that will necessitate understanding how variables work.

What I recommend doing, rather than just asking for some code you don't understand (and what you are asking for is a complete inventory system), you should learn some basic Python so you can do what you want and better understand what help people give you.

Go to codeacademy.com and take their free basic Python course. The whole hing takes maybe 12 hours. You can do it in a weekend and it will make you much better able to do what you are asking as well as help you with everything else you might want to do with your game.

Re: need help with code for a money system

Posted: Thu Aug 13, 2015 3:10 pm
by Lucky1443
Ok thanks

Re: need help with code for a money system

Posted: Thu Sep 17, 2015 6:08 pm
by mediawriterdude
trooper6 wrote:
Lucky1443 wrote: Go to codeacademy.com and take their free basic Python course. The whole hing takes maybe 12 hours. You can do it in a weekend and it will make you much better able to do what you are asking as well as help you with everything else you might want to do with your game.
I don't know if this question has been asked before, but... What recommendations would anyone make on off-line resources for learning Python? Any books?

I currently lack a dedicated internet connection, and learning on-line would be impossible! :cry:

Re: need help with code for a money system

Posted: Thu Sep 17, 2015 6:13 pm
by philat
You can buy Learn Python the Hard Way, which is both more difficult and a bit more tedious than the codecademy course, but available with video classes and a full pdf, which you can just download and print out. You can do the practice questions without an internet connection once you set up python and powershell on your computer. You can also just print out the book part only for free, but do consider supporting the author if you find you're benefiting from the book.

Re: need help with code for a money system

Posted: Sat Sep 19, 2015 4:15 pm
by mediawriterdude
philat wrote:You can buy Learn Python the Hard Way, which is both more difficult and a bit more tedious...
Thank you for the quick reply, philat! I'm gonna look into this. :D