Issues with unlockable endings screen

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
SowaKisa
Newbie
Posts: 5
Joined: Wed Feb 24, 2021 6:31 pm
Contact:

Issues with unlockable endings screen

#1 Post by SowaKisa » Wed Feb 24, 2021 7:02 pm

Hello!

So I have tried making my first game with Ren'Py, and thankfully I'm nearly finished with it! But I decided to add something into my game, and I've been unable to find similar posts on the subject.

I'm very new with Ren'Py, so it might just be an obvious issue I'm having.

My idea was to add another option to my main menu upon completing the game for the first time. I want an endings screen 'imagemap' where the endings change color upon being played.
I've added the option to my menu, and used persistent data to unlock it post game.

I have a working imagemap in my game already, and I assumed it was possible to use the same principle to achieve what I want. But it's not really working out as intended...

First issue:
I have my idle, hover and locked images ready.
I created a new Ren'Py document for the Endings Screen (I've pasted some of the code below)
But even if I set the ending to 'True', it just wont change color to the 'unlocked' color. I can't figure out why, and I feel like I've tried everything.
I also tried defining the endings in the script, making the hotspots clickable and a lot of other things, but with no luck.
Second issue:
I made a 'Return' button that I assumed would allow you to return to the main menu when you clicked that hotspot, but that doesn't seem to be working out either. I've tried hiding the screen, jumping to main menu etc. with no luck. I managed to get the best result with using 'clicked Return', but when clicked while displayed from the menu, it starts a new game.

I don't know it it's because you can't add an imagemap this way to the main menu?

Code: Select all

screen ending():
    imagemap:
        ground "endinglock.png"
        hover "endinghover.png"
        idle "endingunlock.png"

        hotspot (460, 543, 139, 51) clicked Return
        if persistent.atalossforwords:
            hotspot (413, 19, 226, 50)
        if persistent.nohope:
            hotspot (23, 180, 119, 54)
        if persistent.watchingoveryoualways:
            hotspot (727, 532, 302, 43)

init python:
    persistent.atalossforwords = False
    persistent.nohope = False
    persistent.watchingoveryoualways = False
In the Screens.rpy document, I added the 'endings' option by adding:

Code: Select all

if persistent.gameclear == True:
            textbutton _ ("Endings") action ShowMenu("ending")
In the script, I set the endings to true like this:

Code: Select all

$ persistent.watchingoveryoualways = True
Can anyone point me in the right direction? :)

Thanks for the help in advance!"

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Issues with unlockable endings screen

#2 Post by hell_oh_world » Wed Feb 24, 2021 7:12 pm

Not really an example pertaining to your code, but this is just to give you an insight.

Code: Select all

screen something():
  button:
    xfill True
    yfill True
    
    # set the background to white if persistent.ended is not True, otherwise set it to red
    if persistent.ended is None:
      background "#fff"
    elif persistent.ended:
      background "#f00"
I made a 'Return' button that I assumed would allow you to return to the main menu when you clicked that hotspot, but that doesn't seem to be working out either.
hotspot (460, 543, 139, 51) clicked Return should be hotspot (460, 543, 139, 51) action Return() instead, I think.
This Return() only works if you have called the screen and not showed it.

SowaKisa
Newbie
Posts: 5
Joined: Wed Feb 24, 2021 6:31 pm
Contact:

Re: Issues with unlockable endings screen

#3 Post by SowaKisa » Wed Feb 24, 2021 7:28 pm

hell_oh_world wrote:
Wed Feb 24, 2021 7:12 pm
Not really an example pertaining to your code, but this is just to give you an insight.

Code: Select all

screen something():
  button:
    xfill True
    yfill True
    
    # set the background to white if persistent.ended is not True, otherwise set it to red
    if persistent.ended is None:
      background "#fff"
    elif persistent.ended:
      background "#f00"
I made a 'Return' button that I assumed would allow you to return to the main menu when you clicked that hotspot, but that doesn't seem to be working out either.
hotspot (460, 543, 139, 51) clicked Return should be hotspot (460, 543, 139, 51) action Return() instead, I think.
This Return() only works if you have called the screen and not showed it.
Thanks for the help! I tried changing it to action Return, but I get an error:

I'm sorry, but an uncaught exception occurred.
While running game code:
TypeError: unbound method get_tooltip() must be called with Return instance as first argument (got nothing instead)

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Issues with unlockable endings screen

#4 Post by hell_oh_world » Wed Feb 24, 2021 7:41 pm

If you encountered an error kindly share the full traceback (full details on the error, there should be a copy button when the error appears).
and use the [code]your traceback here...[/code] tags in posting the traceback here.

SowaKisa
Newbie
Posts: 5
Joined: Wed Feb 24, 2021 6:31 pm
Contact:

Re: Issues with unlockable endings screen

#5 Post by SowaKisa » Wed Feb 24, 2021 7:50 pm

hell_oh_world wrote:
Wed Feb 24, 2021 7:41 pm
If you encountered an error kindly share the full traceback (full details on the error, there should be a copy button when the error appears).
and use the [code]your traceback here...[/code] tags in posting the traceback here.
Oh sorry, it's here:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
TypeError: unbound method get_tooltip() must be called with Return instance as first argument (got nothing instead)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/ast.py", line 913, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/python.py", line 2111, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/core.py", line 2978, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/core.py", line 3773, in interact_core
    rv = renpy.display.focus.mouse_handler(ev, x, y)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/focus.py", line 411, in mouse_handler
    return change_focus(new_focus, default=default)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/focus.py", line 366, in change_focus
    set_focused(current, newfocus.arg, newfocus.screen)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/focus.py", line 110, in set_focused
    new_tooltip = widget._get_tooltip()
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/behavior.py", line 756, in _get_tooltip
    return get_tooltip(self.action)
  File "C:\Users\Katrine\Downloads\renpy-7.4.0-sdk/renpy/display/behavior.py", line 376, in get_tooltip
    return func()
TypeError: unbound method get_tooltip() must be called with Return instance as first argument (got nothing instead)


User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Issues with unlockable endings screen

#6 Post by hell_oh_world » Wed Feb 24, 2021 8:39 pm

Are you sure you followed what I said exactly? you didn't forget the () on the Return?

SowaKisa
Newbie
Posts: 5
Joined: Wed Feb 24, 2021 6:31 pm
Contact:

Re: Issues with unlockable endings screen

#7 Post by SowaKisa » Wed Feb 24, 2021 8:53 pm

hell_oh_world wrote:
Wed Feb 24, 2021 8:39 pm
Are you sure you followed what I said exactly? you didn't forget the () on the Return?
You're right, I did forget the '()'. It works fine when done through the in game screen, but nothing happens when clicked from the main menu, nothing happens at all. I wonder why?

Also, I messed around with my imagemap. It seems that the hotspots will change color if I assign them a clickable function. I tried using 'Clicked NullAction' but it just acts as the return button does.
And the game doesn't seem to save my persistent data after closing it and opening again. Do you have any idea why? :(

And thanks you so much for helping!

SowaKisa
Newbie
Posts: 5
Joined: Wed Feb 24, 2021 6:31 pm
Contact:

Re: Issues with unlockable endings screen

#8 Post by SowaKisa » Thu Feb 25, 2021 9:02 am

Okay, so I updated my code a bit and figured a few things out.

I added 'Modal True' since you could click on things below the imagemap.
I added == True after all of the endings, and deleted the init python block. That seems to solve the issue with my game not saving the persistent data.

Now my only real issues are the return button not acting as it's supposed to, and the 'NullAction' acting as a Return when clicked, instead of just doing nothing.

Code: Select all

screen ending():
    modal True
    imagemap:
        ground "endinglock.png"
        hover "endinghover.png"
        idle "endingunlock.png"

        hotspot (460, 543, 139, 51) clicked Return()
        if persistent.atalossforwords == True:
            hotspot (413, 19, 226, 50) clicked NullAction

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Issues with unlockable endings screen

#9 Post by hell_oh_world » Thu Feb 25, 2021 8:59 pm

kindly read the official documentation about actions if you can: https://www.renpy.org/doc/html/screen_a ... l#tooltips
it shows some examples of how to use actions properly.
Also, use `action` instead of `clicked` as that is what documented: https://www.renpy.org/dev-doc/html/screens.html#hotspot
I'm quite curious on why this `clicked` action exists in the first place, since afaik they serve the same purpose. But `clicked` is not officially documented though.
Actions always end with ().

cheonbyeol
Regular
Posts: 37
Joined: Thu Feb 04, 2021 9:04 am
Contact:

Re: Issues with unlockable endings screen

#10 Post by cheonbyeol » Thu Feb 25, 2021 9:15 pm

I suggest you set your persistent variables with default:

Code: Select all

default persistent.atalossforwords = False
default persistent.nohope = False
default persistent.watchingoveryoualways = False
What this does: if they do not exist yet, they will be given the default value, and otherwise left as they currently are. (When you just define them, they will be redefined everytime the game restarts.)

For the actions:
I think NoAction() also has the brackets, see if that solves any of the issues?
For the Return() not working, I also had that issue, it's a fickle little thing... You can try adding "tag menu" to the screen code (I think that's what allows it to work on the predefined screens), or change the action to Hide("ending") instead.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]