Variable maths

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
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Variable maths

#1 Post by Scribbles »

I am not good at math.

I was thinking there had to be a way to compare a variable (affection/love points) with an equation that would make it easier during love checks without knowing the exact possible value each and every time. (as it is prone to change)

like.....

Code: Select all

call loveCheckMath

if lovePoints > lovePointAvg:
     "Love check passed."

else:
     "Love check failed"

label loveCheckMath:

     call currentLovePointMax
     call lovePointCount

    $ lovePointAvg = currentLovePointMax / currentLovePointCount

     return

label currentLovePointMax:
     $ currentLovePointMax = #????
     return

label lovePointCount:
     $ currentLovePointCount = #????
     return

how would you go about finding the current love point count and maximum in order to determine the average as the game was played??
I am not even sure what "type" of code to look up for this.
Image - Image -Image

User avatar
morrie
Regular
Posts: 33
Joined: Mon Aug 01, 2016 11:18 am
Tumblr: morrie-games
Contact:

Re: Variable maths

#2 Post by morrie »

I'm not so good at this but couldn't you just add the same + points to the maximum love variable everytime you add + to the current love variable, and never remove points from it. And then everytime points are added you also have an "if maxlove >= currentlove" then don't add points to maxlove (like if current is at 90 but the max was at 100, you'd get an incorrect max number if you added points then.) Something like that anyway.... I don't know.....

To calculate the average you should do $ averagelove = maxlove + currentlove / 2, right?
Edit: whoops sorry I don't know if that's the correct way to write it..... it might be (maxlove + currentlove) / 2 or something to make sure it divides the right number.......

Edit 2: Wait!! To get the max love one couldn't you do it like this everytime you add points? I'm sorry maybe it's dumb....

Code: Select all

$ maxlove = 0
$ currentlove = 0

# Positive event happens..... 
$ currentlove + 10
# Check if maxlove should be updated after this event 
if currentlove >= maxlove: 
    $ maxlove = currentlove
*perpetual beginner who can't wrap my head around coding....*

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Variable maths

#3 Post by trooper6 »

I have a lot of things to say about how you are writing your code. Basically, you need to use functions. Let's ask about the question, "how would you go about finding the current love point count and maximum in order to determine the average as the game was played?"

Following on morrie,

You need to declare a max_love and a current_love variable--which should be done using default. And everytime a situation comes up where points could be gained you should add the max to the max_love and add whatever points they earned to current_love.

This does that:

Code: Select all

default max_love = 0
default current_love = 0
default average_love = 0

label start:
    scene black
    
    "You are walking down the street."
    "You see a rose."
    menu:
        "What do you do?"
        "Pick up the rose":
            $current_love+= 10
        "Ignore the rose":
            $current_love+= 5
        "Stomp on the rose":
            $current_love+= 0
    $max_love +=10
    
    "A friend tells you it is Valentines day."
    
     menu:
        "How do you respond?"
        "Explain how much you love Valentine's Day":
            $current_love+= 10
        "Thinks that's cool, but it is no big deal.":
            $current_love+= 5
        "Yell about how terrible Valentine's Day is":
            $current_love+= 0
    $max_love +=10
So after the first menu, the max number of points you could have is 10; after the second menu, the max number of points you could have is 20.

Let's get to the second question I have. I don't really know what you want to do with calculating your average...especially if you want to do a check where current_love being over average means a passed check.

Let's look at every possibility for what you've laid out in your initial post:

After Menu 1:
a) max_love (10)/current_love (10) = 1. Is current love greater than 1? Yes. Check Passed.
b) max_love (10)/current_love (5) = 2. Is current love greater than 2? Yes. Check Passed.
c) max_love (10)/current_love (0) = ERROR.

After Menu 2:
a1) max_love (20)/current_love (20) = 1. Is current love greater than 1? Yes. Check Passed.
a2) max_love (20)/current_love (15) = 1.3 Is current love greater than 1.3? Yes. Check Passed.
a3) max_love (20)/current_love (10) = 2. Is current love greater than 2? Yes. Check Passed.
b1) max_love (20)/current_love (15) = 1.3 Is current love greater than 1.3? Yes. Check Passed.
b2) max_love (20)/current_love (10) = 2. Is current love greater than 2? Yes. Check Passed.
b3) max_love (20)/current_love (5) = 4. Is current love greater than 4? Yes. Check Passed.
c1) max_love (20)/current_love (10) = 2. Is current love greater than 2? Yes. Check Passed.
c2) max_love (20)/current_love (5) = 4. Is current love greater than 4? Yes. Check Passed.
c3) max_love (20)/current_love (0) = ERROR.

So you are either always going to pass the check or get an error. So what you are doing isn't going to be useful. Also, that isn't how you calculate an average.

How do you calculate the average? You add all the numbers together and then divide by how many numbers there are.

The average of 10+5+0 (the number of point choices for the first menu) is: 10+5+0 = 15/3 = 5.
The average of 10+5+0+10+5+0 (the number of choices for both menus) is: 10+5+0+10+5+0 = 30/6 = 5

If you went by average...then it would be useful after the first menu...but not that useful after the second menu and later menus...because with each subsequent set of choices, you will have a better chance of beating it.

So, if you really want to do this thing you are thinking of, I think you should go with percentages. Decide what is a passing percentage and check to see if your person hast that at any given time.

So how to calculate percentages? x = current_love * 100 / max_love

After Menu 1:
a) current_love (10) * 100 / max_love (10) = 100%
b) current_love (5) * 100 / max_love (10) = 50%
c) current_love (0) * 100 / max_love (10) = 0%

After Menu 2:
a1) current_love (20) * 100 / max_love (20) = 100%.
a2) current_love (15) * 100 / max_love (20) = 75%.
a3) current_love (10) * 100 / max_love (20) = 50%.
b1) current_love (15) * 100 / max_love (20) = 75%.
b2) current_love (10) * 100 / max_love (20) = 50%.
b3) current_love (5) * 100 / max_love (20) = 25%.
c1) current_love (10) * 100 / max_love (20) = 50%.
c2) current_love (5) * 100 / max_love (20) = 25%.
c3) current_love (0) * 100 / max_love (20) = 0%.

So if you go with percentages, you have to decide what a passing percentage is. Let's say that you decide 70% is passing. So you make a percentage and then check to see if it is greater than 70%.

All of this can be done with a function, not any of this strange label thing you've got going on.

Check out this code that is just an example of something you could do on this concept using a function and the renpy.notify function:

Code: Select all

init -1 python:     
    def love_check():
        global max_love
        global current_love
        percent = (current_love * 100)/max_love
        if percent >= 70:
            renpy.notify("Love Check Passed")
            return True
        else:
            renpy.notify("Love Check Failed")
            return False

# The game starts here.

default max_love = 0
default current_love = 0

label start:
    scene black
    
    "You are walking down the street."
    "You see a rose."
    menu:
        "What do you do?"
        "Pick up the rose":
            $current_love+= 10
        "Ignore the rose":
            $current_love+= 5
        "Stomp on the rose":
            $current_love+= 0
    $max_love +=10
    
    $love_check()
        
    "A friend tells you it is Valentines day."
    
    menu:
        "How do you respond?"
        "Explain how much you love Valentine's Day":
            $current_love+= 10
        "Thinks that's cool, but it is no big deal.":
            $current_love+= 5
        "Yell about how terrible Valentine's Day is":
            $current_love+= 0
    $max_love +=10

    $love_check()

    "Now let's say you want to do something in terms of using that True/False that is returned from your function."
    $result = love_check()
    "You see an attractive sort of person walking down the street."
    menu:
        "What do you do?"
        "Ignore the person.":
            jump alone
        "Say Hello.":
            jump friendship
        "Flirt" if result:
            jump romance
            
label alone:
    "You walk past the attractive sort of person and think...whatever."
    "You go home and hang out with your freinds. You are happy and have no drama."
    "The end."
    
label friendship:
    "The attractive person says 'hi' back to you. They say their name is Jess and that they are new in town."
    menu:
        "What do you say?"
        "You flirt a bit and say you could give them a tour of the city":
            $current_love += 7
        "You keep it friendly and offer to invite them to to your game night with freinds.":
            $current_love += 3
    $max_love += 10
    
    $love_check()
    
    "The story continues on."
    jump test_end
    
label romance:
    "The attractive person blushes and smiles. They say their name is Jess and that they are new in town."
    menu:
        "What do you say?"
        "You flirt a bit and say you could give them a tour of the city":
            $current_love += 10
        "You keep it friendly and offer to invite them to to your game night with freinds.":
            $current_love += 5
    $max_love += 10
    
    $love_check()
    
    "The story continues on."
    jump test_end
    

label test_end:
    
    "Test over"
    return
If you have never taken the Basic Python course at codeacademy.com, you really should try that course.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Variable maths

#4 Post by Scribbles »

thanks guys!

and trooper6 I will look into that course! :)
Image - Image -Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]