Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Sat May 25, 2013 5:33 am

All times are UTC - 5 hours [ DST ]


Forum rules


Ask questions about one topic per thread, and use a descriptive subject. "NotImplemented error in script.rpy" is a good subject, "Tom's problems" is not. Remember to include all of traceback.txt or error.txt when reporting a problem, as well as the relevant lines of script. Use the [code] tag to format scripts.



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Aug 20, 2012 1:11 pm 
Regular
User avatar

Joined: Mon Oct 03, 2011 7:27 pm
Posts: 149
Location: USA
Completed: Lady Luck's Due: BlackJack
Projects: Golden Cauldron
I've been looking for an answer, but I'm not sure this is right. I have a basic payday system where you get paid on the 28th. It activates right, but it doesn't do the math. Did I write it wrong?

Code:
    if day == 28: #Payday
        if LDeductions = True: #Late last month take 10% from pay.
            $ pay += (((baserate * PLevel) * 28) - 10%)
        else:
            $ pay += ((baserate * PLevel) * 28) #base rate (5 x PlayerLevel) x 28 days.
        ttext "After deductions I recieve [pay] gold."
        $ coins += pay
        $ pay = 0

_________________
I ❤ Code!
"At the back of my thoughts was the child wondering if she'd see her friend today.
I couldn't tell her the truth."


Current Projects:
Golden Cauldron - Development Blog
Lady Luck's Due: Blackjack ~ 100% Done! Topic Here


Last edited by wyverngem on Mon Aug 20, 2012 9:03 pm, edited 1 time in total.

Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 1:20 pm 
Veteran
User avatar

Joined: Thu Jan 28, 2010 2:31 am
Posts: 291
Location: Singapore
Completed: Culina: The Spirit of Cooking
Projects: Love at the Laundromat, Culina: Hands in the Kitchen
Organization: Moustachio Studios
The problem is the %. that's not 10%, that's the modulo operator which is really confusing to people starting out with programming.

What you could do is:
Code:
$ pay =  (((baserate * PLevel) * 28) )
$ deductions = pay * .1
#assuming you what a whole number
$pay = int(pay - deductions)


That help?

_________________

Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter - Check out my 2D Platformer: Lunaris
Experienced in: C/C++, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."


Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 1:53 pm 
Regular
User avatar

Joined: Mon Dec 07, 2009 5:01 am
Posts: 106
Projects: Undecided
Instead of adding a variable, you could just multiply by 0.9, and then convert to integer
Code:
$ pay += int(0.9*((baserate * PLevel) * 28))

and shouldn't
Code:
if LDeductions = True:
be like this?
Code:
if LDeductions == True:

_________________
My avatar art is a freebie by SilverHyena. Thanks a lot!


Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 1:55 pm 
Veteran
User avatar

Joined: Wed Nov 18, 2009 11:17 am
Posts: 359
Location: Germany
Completed: Loren
Projects: PS2
Even better would be:
Code:
if LDeductions:

It's the same as Minnfae version, but more in line with python style.

_________________
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase II


Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 6:23 pm 
Regular
User avatar

Joined: Mon Oct 03, 2011 7:27 pm
Posts: 149
Location: USA
Completed: Lady Luck's Due: BlackJack
Projects: Golden Cauldron
Okay, I figured the out the percent, the first example works out great. I have a second problem. Every time I use this even in a call it runs twice. Giving the payday out twice. What happened?

Code:
label PayRent: #Payday and rent events.
    if day == 3:
        if coins >= rent:
            $ coins -= rent
            if LDeduction == True:
                "There, I was able to finally pay rent on time."
                $ LDeduction = False
                $ PDeduction = 0
            else:
                ttext "Room and board are always due on the 3rd of every season. Paid [rent] for rent."
                jump dayplanner
        else:
            if LDeduction == True:
                $ coins = (coins * 0.75)
                ttext "Again! I don't have rent, well here's 75 percent of what I have now I guess...I'm going to be dudcuted an additional 10 percent!"
                $ PDeduction += 0.1
            else:
                $ coins = (coins * 0.75)               
                ttext "I don't have enough for rent! I'll have to pay 75 percent of what I have now I guess..."
                $ LDeduction = True
                $ PDeduction += 0.1
    if day == 28: #Payday
        if LDeduction == True: #Late last month take 10% from pay.
            if PLevel == 0: #This is just a safeguard if you're still level 0 the first month. I hope not!
                $ pay = ((baserate * (PLevel + 1)) * day)
                $ deductions = int(pay * PDeduction)
                $ pay = int(pay - deductions)
            else:
                $ pay += (((baserate * PLevel) * day) - 10)
                $ deductions = int(pay * PDeduction)
                $ pay = int(pay - deductions)
        elif LDeduction == False:
            if PLevel == 0: #This is just a safeguard if you're still level 0 the first month. I hope not!
                $ pay += ((baserate * (PLevel + 1)) * day)
            else:
                $ pay += ((baserate * PLevel) * day) #base rate (5 x PlayerLevel) x 28 days.
        ttext "After deductions I recieve [pay] gold."
        $ coins += pay
        $ pay = 0
return

_________________
I ❤ Code!
"At the back of my thoughts was the child wondering if she'd see her friend today.
I couldn't tell her the truth."


Current Projects:
Golden Cauldron - Development Blog
Lady Luck's Due: Blackjack ~ 100% Done! Topic Here


Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 6:41 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10780
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
It's hard to say, since we don't know what you intended.

It looks like you're mostly incrementing pay (+=) rather than assigning it (=), so that could be the cause.

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
 Post subject: Re: Coding Math Problem
PostPosted: Mon Aug 20, 2012 9:02 pm 
Regular
User avatar

Joined: Mon Oct 03, 2011 7:27 pm
Posts: 149
Location: USA
Completed: Lady Luck's Due: BlackJack
Projects: Golden Cauldron
Hmm, when I switched the day == 28 and day == 3 around ti ended up working fine. Probably just a way it's stated.

_________________
I ❤ Code!
"At the back of my thoughts was the child wondering if she'd see her friend today.
I couldn't tell her the truth."


Current Projects:
Golden Cauldron - Development Blog
Lady Luck's Due: Blackjack ~ 100% Done! Topic Here


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Myra


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group