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.
-
sdx231
- Newbie
- Posts: 3
- Joined: Wed Nov 25, 2020 2:25 am
-
Contact:
#1
Post
by sdx231 » Wed Nov 25, 2020 4:20 am
I've had some experince with Object-Oriented Programming before on C++, but now I'm trying to uderstand how it works on Python.
So... I need help.
Code: Select all
init python:
max = 100
class Check(renpy.Displayable):
def __init__(self, xpos, ypos):
super(Check, self).__init__()
self.posx = xpos
self.posy = ypos
screen scr_strmg():
imagebutton align(0.5,0.6):
idle "button/button1.png" #draws idle button
selected "button/button2.png" #draws pressed button
action Notify("...")
add "gaugage/gaugage.png" align(0.5,0.25) #draws gaugage
add Check("check/check.png"):
xalign 0.5
yalign 0.15
The message I get:
Code: Select all
While running game code:
File "game/script.rpy", line 12, in script
$renpy.call_screen("scr_strmg")
File "game/script.rpy", line 12, in <module>
$renpy.call_screen("scr_strmg")
File "game/strength_v1.rpy", line 23, in execute
screen scr_strmg():
File "game/strength_v1.rpy", line 23, in execute
screen scr_strmg():
File "game/strength_v1.rpy", line 30, in execute
add Check("check/check.png"):
TypeError: __init__() takes exactly 3 arguments (2 given)
-
hell_oh_world
- Miko-Class Veteran
- Posts: 665
- Joined: Fri Jul 12, 2019 5:21 am
- Projects: The Button Man
- Organization: NILA
- Github: hell-oh-world
- Location: Philippines
-
Contact:
#2
Post
by hell_oh_world » Wed Nov 25, 2020 4:26 am
Your constructor init accepts 2 parameters xpos and ypos and when you created an instance of it in the screen you only passed one which is the string name of the image. Also, the Displayable class requires you to override its methods including render and event, look into the docs about Creator Defined Displayables for more info. self is an argument placeholder for the instance it self, so your class methods should always have one argument atleast where the instance is passed first once created. The error says your constructor requires 3 arguments, self, xpos and ypos, the instance itself is passed first to the self arg, then the remaining 2 are for you to provide. You can consider self as the `this` keyword, if you're from another language, etc.
https://www.renpy.org/doc/html/udd.html ... isplayable
-
sdx231
- Newbie
- Posts: 3
- Joined: Wed Nov 25, 2020 2:25 am
-
Contact:
#3
Post
by sdx231 » Wed Nov 25, 2020 5:26 am
Now I get it. Thank you.
I'll check the docs again.