[Solved] Function keeps repeating on a button

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] Function keeps repeating on a button

#1 Post by Lezalith » Sun Feb 26, 2017 7:40 am

Hey Forum, I hope you're all having a wonderful day.

So, I started changing parts of my code.
How it used to be: From the Study screen, button A has an action Jump("moodMath"), label moodMath does math with plenty variables, and at the end of that label is a call "afterTeaching" screen, that shows results of the math.
How I want it now: From the Study screen, button A has actions TeachingDoneMorning() and Show("afterTeaching", transition=dissolve). afterTeaching shows results of the math.

What you see below is part of the code of (what used to be) moodMath label and (what is now) TeachingDoneMorning function.
For the "if InTeachingMorning", there are 36 options, but the InTeachingMorning variable starts unselected (Value of 0).
The code basically takes a skill (Ammo skill here) then does math with your current mood, and based on that adds value to the selected skill.

Code: Select all

if InTeachingMorning == "Ammo":
    skillValueOld = AmmoValue
    MoodAffection = (MoodRelaxed - MoodAfraid)
    if MoodAffection > 0:
        MoodAffection = MoodAffection + 2
    else:
        pass
    TeachingPoints = (MoodAffection + 6)*1.66667
    AmmoValue = (skillValueOld + TeachingPoints)
    AmmoValue = round(AmmoValue, 3)
    skillValueNew = AmmoValue
if skillValueNew >= 100:
    skillValueNew = 100
Problem: Once one of the options is selected (Option "Ammo" displayed here), every click on that screen triggers this function.

It looks like the button is covering the entire screen.
There are two things my mind fails to comprehend.

ONE)

Code: Select all

action Show("emptyBranch"),TeachingDoneMorning(),Show("teaching_done_morning", transition=dissolve),Hide("study")
These are the functions attached to that button. Part of TeachingDoneMorning() is the code above. If you delete that function from the button's actions, the problem disappears.
So it has to be the actions triggering that's causing it. Triggering on every click.
But only TeachingDoneMorning() is triggering. Neither Show("emptyBranch"), nor Show("teaching_done_morning"), nor Hide("study") are trigerring.

TWO)
For the button to be clickable in the first place, two variables (InTeachingMorning and InTeachingAfternoon) have to be selected.
But in my case, I only select InTeachingMorning.

You see?
Again.
1) You can't click the button (It is under showif and doesn't meet the conditions for showif to be true).
2) The button triggers from anywhere of the screen.
3) After triggering the button, only one of it's actions triggers.

I don't understand it.
Last edited by Lezalith on Sun Feb 26, 2017 8:19 am, edited 2 times in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Function keeps repeating on a button you can't even clic

#2 Post by Ocelot » Sun Feb 26, 2017 7:49 am

Actions are not functions. They are complex objects. The only reason you do not have a crash here, is because RenPy accesses additional methods only from first action. Place your function first in list, and you get crash.

The capital letter would give you a hint, if you knew Python: fuctions begins from lowercase letter, classes begin from uppercase one.

To call a function as part of action, you should use Function action. In your case it would be:

Code: Select all

action [ Show("emptyBranch"), Function(TeachingDoneMorning), Show("teaching_done_morning", transition=dissolve), Hide("study") ]
Notice, that action takes list, not tuple. It might work now, but it might stop working later. Better use what documentation tells you to. I would rename function to teaching_done_morning in accordance to PEP8.
Last edited by Ocelot on Sun Feb 26, 2017 8:17 am, edited 1 time in total.
< < insert Rick Cook quote here > >

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

Re: Function keeps repeating on a button you can't even clic

#3 Post by Lezalith » Sun Feb 26, 2017 8:15 am

Oh, alright. That explains a lot.

Any idea why I still get "'str' object is not callable" error?

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Function keeps repeating on a button you can't even clic

#4 Post by Ocelot » Sun Feb 26, 2017 8:17 am

Sorry, my mistake. Drop the quotes around function name.
< < insert Rick Cook quote here > >

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

Re: Function keeps repeating on a button you can't even clic

#5 Post by Lezalith » Sun Feb 26, 2017 8:19 am

You're sorry?
I wanna kiss you right now.

Thanks so much!

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_