[Solved] Simple math problem

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

[Solved] Simple math problem

#1 Post by Lezalith » Tue Sep 27, 2016 1:10 pm

Hey everyone, hope you're having a nice day.

Weeks! Long periods of time. On every fourth week, I want to decrease the supplies. This should do just fine:

Code: Select all

label newWeek:
    $ renpy.checkpoint()
    $ Week += 1
    
    if Week / 4 == 0:
        $ supplies -= 1
    else:
        pass
I once saw a tip on the internet. A guy was asking how can you tell whether the value is odd or even. The answer was simple: Divide it by 2 and check if it's zero, only even numbers work like that. So I thought of the same thing.
Week is divided by 4. Of course, this will be 0 only once every 4 weeks. Why does it do -1 supplies *every* week then? :C
Last edited by Lezalith on Fri Sep 30, 2016 7:09 pm, edited 1 time in total.

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: Simple math problem

#2 Post by papiersam » Tue Sep 27, 2016 2:08 pm

I think you're looking for modulo.

Because if weeks is 4, then 4/4 is 1, and that evaluates to true. But 4%4 is 0 (meaning 0 remainder).

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: Simple math problem

#3 Post by Lezalith » Tue Sep 27, 2016 3:37 pm

4 divided by 4 equals 1... God, I feel dumb.

Anyway, how does that work? "Evaluates to true"? I mean, my code was ==0, so that shouldn't work either way..

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: Simple math problem

#4 Post by papiersam » Tue Sep 27, 2016 3:44 pm

I suppose. When I tested your code, it didn't change the supplies value at all (which was expected). I applied your code herein with the modulo:

Code: Select all

label newWeek:
    $ renpy.checkpoint()
    $ Week += 1
    
    if Week % 4 == 0:
        $ supplies -= 1
    else:
        pass
        
    return
    
label start:
    
    $Week = 0
    $supplies = 15
    
    while supplies:
        
        "Week [Week] // Supplies [supplies]"
        call newWeek
And it seems to work just fine.

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_