[SOLVED] Error in Mini-game 'Click and hold'

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
Emperoxxx Anime
Newbie
Posts: 10
Joined: Wed Jul 12, 2023 6:48 am
Projects: KonoSuba - The Harem Adventures
Deviantart: emperoxxxanime
Discord: emperoxxx
Contact:

[SOLVED] Error in Mini-game 'Click and hold'

#1 Post by Emperoxxx Anime »

I was trying out a mini game -
Andredron wrote: Mon Dec 12, 2022 9:02 am
Honestly I could barely find the link on the Internet to download and then re-publish your project
This one, but the game 'Kissing booth' which is a game of click and hold throws the following error when I hold the button for the maximum time -

Code: Select all

I'm sorry, but an uncaught exception occurred.

While loading <renpy.display.im.Crop object at 0x00000000054ad0d0>:
  File "game/script.rpy", line 304, in script
    python:
  File "game/script.rpy", line 309, in <module>
    winner = ui.interact(suppress_overlay=True, suppress_window=True)
  File "game/kissing_booth.rpy", line 55, in render
    eileen = renpy.render( temp_meter, width, height, st, at)
error: subsurface rectangle outside surface area.

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

Full traceback:
  File "game/script.rpy", line 304, in script
    python:
  File "renpy-8.1.1-sdk\renpy\ast.py", line 1138, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy-8.1.1-sdk\renpy\python.py", line 1122, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 309, in <module>
    winner = ui.interact(suppress_overlay=True, suppress_window=True)
  File "renpy-8.1.1-sdk\renpy\ui.py", line 299, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy-8.1.1-sdk\renpy\display\core.py", line 3579, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
  File "renpy-8.1.1-sdk\renpy\display\core.py", line 4172, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "renpy-8.1.1-sdk\renpy\display\core.py", line 2779, in draw_screen
    surftree = renpy.display.render.render_screen(
  File "render.pyx", line 492, in renpy.display.render.render_screen
  File "render.pyx", line 266, in renpy.display.render.render
  File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "game/kissing_booth.rpy", line 55, in render
    eileen = renpy.render( temp_meter, width, height, st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "renpy-8.1.1-sdk\renpy\display\im.py", line 676, in render
    return cache.get(self, render=True)
  File "renpy-8.1.1-sdk\renpy\display\im.py", line 330, in get
    surf = image.load()
  File "renpy-8.1.1-sdk\renpy\display\im.py", line 1192, in load
    return cache.get(self.image).subsurface((self.x*os, self.y*os,
  File "src/pygame_sdl2/surface.pyx", line 642, in pygame_sdl2.surface.Surface.subsurface
error: subsurface rectangle outside surface area.

Windows-10-10.0.22000 AMD64
Ren'Py 8.1.1.23060707
Fall Fair 0.0
Wed Jul 12 16:21:40 2023
The game script it -

Code: Select all

init:
    python:
        import math

        from vec2d import vec2d
        class KissingBoothDisplayable(renpy.Displayable):
            def __init__(self, time_limit, time_target):
                renpy.Displayable.__init__(self)
                
                self.time_limit = time_limit
                self.time_target = time_target
                
                
                # Some displayables we use.
                self.panel = Image("images/panel.png")
                self.meter = Image("images/meter.png")
                self.arrow = Image("images/arrow.png")
                self.ctb = Text("Click and Hold to start kissing.", size=36, drop_shadow=(2,2), drop_shadow_color="#C0C0C0")
                
                # The sizes of some of the images.
                self.METER_WIDTH = 50.0
                self.METER_HEIGHT = 400.0
                
                # Started.
                self.started = False
                
                # The time of the past render-frame.
                self.oldst = None
                self.time_passed = 0.0
                
            def score(self):
                return math.fabs(self.time_target-self.time_passed)
                
            # draws the screen.
            def render(self, width, height, st, at):
                # Figure out the time elapsed since the previous frame.
                if self.oldst is None and self.started:
                    self.oldst = st
                if self.started:    
                    self.time_passed = st - self.oldst
                # The Render object we'll be drawing into.
                r = renpy.Render(width, height)
                
                
                pixel_height = self.METER_HEIGHT * (self.time_passed/self.time_limit)
                target_height = self.METER_HEIGHT - (self.METER_HEIGHT * (float(self.time_target)/float(self.time_limit)))
                
                
                eileen = renpy.render( self.panel, width, height, st, at)
                ew, eh = eileen.get_size()
                r.blit(eileen, (width*0.75 - ew / 2, height/2 - eh/ 2))
                
                
                temp_meter = im.Crop(self.meter,0,self.METER_HEIGHT-pixel_height,self.METER_WIDTH,pixel_height)
                eileen = renpy.render( temp_meter, width, height, st, at)
                r.blit(eileen, (width*0.75 - self.METER_WIDTH / 2, height/2 + self.METER_HEIGHT/ 2-pixel_height))
                       
                meter = renpy.render( self.arrow, width, height, st, at)
                ew, eh = meter.get_size()
                r.blit(meter, (width*0.75 - self.METER_WIDTH / 2, (height/2) - (self.METER_HEIGHT/ 2) + target_height - (eh / 2)))
                
                # Show the "Click to Begin" label.
                if self.started == False:
                    ctb = renpy.render(self.ctb, 800, 600, st, at)
                    cw, ch = ctb.get_size()
                    r.blit(ctb, (width*0.5 - cw / 2, height*0.25 - ch/2)) 
                    

                # Ask that we be re-rendered ASAP, so we can show the next
                # frame.
                renpy.redraw(self, 0)
                
                # Return the Render object.
                return r
            
            # Handles events.
            def event(self, ev, x, y, st):
                import pygame
                
                # Mousebutton down == start the game by setting stuck to
                # false.
                if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
                    self.started = True
                if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1 and self.started:
                    return  self.score()
                if self.started:
                    if self.time_passed < self.time_limit:
                        raise renpy.IgnoreEvent()
                    else:
                        return self.score()
                else:
                    raise renpy.IgnoreEvent()

The script to run the game is

Code: Select all

label kissing_booth:
    scene bg gym full
    $ customers = 0
    $ booth_shifts += 1
        
    
label kb_customer:
    if alignment > 0 and donations > 20 and booth_shifts == 2 and customers == 4:
        hide customer
        show robert normal behind table 
        mc "I didn't expect to see you here."
        robert "Everyone needs to do their part for all the clubs."
        "Robert leans in:"
        robert "Plus, I suspect I will enjoy it."
        scene robert_kiss
        "..."
        jump choose_game
    elif alignment < 0 and experiences > 20 and booth_shifts == 2 and customers == 4:
        hide customer
        show kyle normal behind table 
        mc "This must be my lucky day!"
        kyle "No. Actually I think it is mine."
        scene kyle_kiss
        "..."
        jump choose_game
    elif alignment == 0 and tickets > 50 and booth_shifts == 2 and customers == 4:
        hide customer
        show mark normal behind table 
        mc "What are you doing here?"
        "Mark pushes his glasses up his nose."
        mark "Just helping out for the sake of the Drama Club."
        mc "For the sake of the Drama Club."
        jump choose_game
    else:
        show customer  
    show table
    python:
        customers += 1
        tips = 0 
        randfloat = renpy.random.random() * 2.0 + 0.5
        ui.add(KissingBoothDisplayable(2.5,randfloat))
        winner = ui.interact(suppress_overlay=True, suppress_window=True)

    window show None
    python:
        if winner < 0.1:
            tips = int((0.1 - winner) * 50)
            tickets += tips 
            
    "You earned [tips] tickets in tips."
    
    if customers < 5:
        jump kb_customer
        
    
    jump choose_game
    
Please can anyone help me resolve the error, I'm kinda new to renpy.

There's one vector 2d file for all the mathematical operands. I'm not sure if it's involved with the error or not.
Last edited by Emperoxxx Anime on Fri Jul 28, 2023 10:01 am, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Error in Mini-game 'Click and hold'

#2 Post by _ticlock_ »

Emperoxxx Anime wrote: Thu Jul 27, 2023 2:21 pm
It seems the error is triggered at this line:

Code: Select all

eileen = renpy.render( temp_meter, width, height, st, at)
Look at the following lines:

Code: Select all

pixel_height = self.METER_HEIGHT * (self.time_passed/self.time_limit)

Code: Select all

      
temp_meter = im.Crop(self.meter,0,self.METER_HEIGHT-pixel_height,self.METER_WIDTH,pixel_height)
pixel_height can be bigger than self.METER_HEIGHT when self.time_passed > self.time_limit. Likely the error due to messed up crop boundaries.
You can limit pixel_height and check if it solves the problem:

Code: Select all

pixel_height = min(self.METER_HEIGHT * (self.time_passed/self.time_limit), self.METER_HEIGHT)

Emperoxxx Anime
Newbie
Posts: 10
Joined: Wed Jul 12, 2023 6:48 am
Projects: KonoSuba - The Harem Adventures
Deviantart: emperoxxxanime
Discord: emperoxxx
Contact:

Re: Error in Mini-game 'Click and hold'

#3 Post by Emperoxxx Anime »

_ticlock_ wrote: Thu Jul 27, 2023 6:10 pm

Hey, Thanks a lot for the reply and a clear explanation. The bug seems fixed now!

Post Reply

Who is online

Users browsing this forum: Dark12ose