PW Shake effect not working

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
thooruchan
Regular
Posts: 47
Joined: Wed Sep 03, 2014 1:48 pm
Completed: The Festival, a YGO fangame
Projects: Charming Monsters (WIP)
Organization: DrawOrDrop Studio
Tumblr: thooruchan
Deviantart: thooruchan
Skype: thooru-chan
Location: Spain
Contact:

PW Shake effect not working

#1 Post by thooruchan » Sun Dec 07, 2014 7:08 am

Hello, I have been having trouble with the Phoenix Wright shake effect.
When I first tried it on a test game, I copied the code as if, and it worked perfectly, However when I do it on my game, it always gives me the same error.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/sidsimconvo.rpy", line 358, in script
    show sids at center, Shake(None, 0.5, dist=5)
  File "game/sidsimconvo.rpy", line 358, in <module>
    show sids at center, Shake(None, 0.5, dist=5)
NameError: name 'Shake' is not defined
I copied the shake code on it's own .rpy file, and it doesn't give me any trouble. It's when I try to define the effect, either on a new init: block ,or defining it, for example, along images, that it gives me an error.
The line i talk about is:

Code: Select all

init:
    $ sshake = Shake((0, 0, 0, 0), 1.0, dist=15)
I have no idea of what is wrong, because when I tried it before, it worked.
Sometimes i've found that some tutorials where it uses $, I have to change it for 'define', but in this case it didn't work
I use renpy 6.18.3 761

I would be really grateful for some help. It's a small detail that I would really like to be able to add to the game I'm making, if possible.
Image
Charming Monsters, the webcomic Visual Novel BL game.

User avatar
MoonStar
Regular
Posts: 163
Joined: Mon Jun 09, 2014 10:21 am
Projects: Yggdrasil
Contact:

Re: PW Shake effect not working

#2 Post by MoonStar » Sun Dec 07, 2014 7:18 am

I use it also and it works for me.

shake.rpy (in my case)

Code: Select all

init:

    python:
    
        import math

        class Shaker(object):
        
            anchors = {
                'top' : 0.0,
                'center' : 0.5,
                'bottom' : 1.0,
                'left' : 0.0,
                'right' : 1.0,
                }
        
            def __init__(self, start, child, dist):
                if start is None:
                    start = child.get_placement()
                #
                self.start = [ self.anchors.get(i, i) for i in start ]  # central position
                self.dist = dist    # maximum distance, in pixels, from the starting point
                self.child = child
                
            def __call__(self, t, sizes):
                # Float to integer... turns floating point numbers to
                # integers.                
                def fti(x, r):
                    if x is None:
                        x = 0
                    if isinstance(x, float):
                        return int(x * r)
                    else:
                        return x

                xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]

                xpos = xpos - xanchor
                ypos = ypos - yanchor
                
                nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
                ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)

                return (int(nx), int(ny), 0, 0)
        
        def _Shake(start, time, child=None, dist=100.0, **properties):

            move = Shaker(start, child, dist=dist)
        
            return renpy.display.layout.Motion(move,
                          time,
                          child,
                          add_sizes=True,
                          **properties)

        Shake = renpy.curry(_Shake)
then i use this in my script.rpy

Code: Select all

narator "{size= 50}Before I can think of an answer I feel 
as if the earth is shaking more and more intensely...... {w=5}Several seconds later it stops.{/size}" with Shake((0, 0, 0, 0), 5.0, dist=30)
and works every time you dont need to do any init in script.rpy only call it with "with Shake" and give him the right parameters.

User avatar
thooruchan
Regular
Posts: 47
Joined: Wed Sep 03, 2014 1:48 pm
Completed: The Festival, a YGO fangame
Projects: Charming Monsters (WIP)
Organization: DrawOrDrop Studio
Tumblr: thooruchan
Deviantart: thooruchan
Skype: thooru-chan
Location: Spain
Contact:

Re: PW Shake effect not working

#3 Post by thooruchan » Sun Dec 07, 2014 6:06 pm

I get the same, it keeps telling me Shake is not defined. :(
I just don't know what the problem is anymore
Image
Charming Monsters, the webcomic Visual Novel BL game.

User avatar
MoonStar
Regular
Posts: 163
Joined: Mon Jun 09, 2014 10:21 am
Projects: Yggdrasil
Contact:

Re: PW Shake effect not working

#4 Post by MoonStar » Sun Dec 07, 2014 6:36 pm

thooruchan wrote:I get the same, it keeps telling me Shake is not defined. :(
I just don't know what the problem is anymore
did you put shake.rpy code in a separate rpy file? and then just ran/called the shake command with "with shake..." at the end of the line where you want to cause the shake?

it may be helpful if you post or attach the files to view them and see whats the problem.

User avatar
thooruchan
Regular
Posts: 47
Joined: Wed Sep 03, 2014 1:48 pm
Completed: The Festival, a YGO fangame
Projects: Charming Monsters (WIP)
Organization: DrawOrDrop Studio
Tumblr: thooruchan
Deviantart: thooruchan
Skype: thooru-chan
Location: Spain
Contact:

Re: PW Shake effect not working

#5 Post by thooruchan » Sun Dec 07, 2014 6:57 pm

MoonStar wrote:
thooruchan wrote:I get the same, it keeps telling me Shake is not defined. :(
I just don't know what the problem is anymore
did you put shake.rpy code in a separate rpy file? and then just ran/called the shake command with "with shake..." at the end of the line where you want to cause the shake?

it may be helpful if you post or attach the files to view them and see whats the problem.
I did all of that. I also put the line

Code: Select all

init:
    $ sshake = Shake((0, 0, 0, 0), 1.0, dist=15)
and that's when I start getting the error. no matter if I use "at Shake" or "with Shake", I always get the same message.
Image
Charming Monsters, the webcomic Visual Novel BL game.

User avatar
MoonStar
Regular
Posts: 163
Joined: Mon Jun 09, 2014 10:21 am
Projects: Yggdrasil
Contact:

Re: PW Shake effect not working

#6 Post by MoonStar » Sun Dec 07, 2014 7:46 pm

thooruchan wrote:
MoonStar wrote:
thooruchan wrote:I get the same, it keeps telling me Shake is not defined. :(
I just don't know what the problem is anymore
did you put shake.rpy code in a separate rpy file? and then just ran/called the shake command with "with shake..." at the end of the line where you want to cause the shake?

it may be helpful if you post or attach the files to view them and see whats the problem.
I did all of that. I also put the line

Code: Select all

init:
    $ sshake = Shake((0, 0, 0, 0), 1.0, dist=15)
and that's when I start getting the error. no matter if I use "at Shake" or "with Shake", I always get the same message.
attach your script or paste the code here pls

User avatar
thooruchan
Regular
Posts: 47
Joined: Wed Sep 03, 2014 1:48 pm
Completed: The Festival, a YGO fangame
Projects: Charming Monsters (WIP)
Organization: DrawOrDrop Studio
Tumblr: thooruchan
Deviantart: thooruchan
Skype: thooru-chan
Location: Spain
Contact:

Re: PW Shake effect not working

#7 Post by thooruchan » Mon Dec 08, 2014 10:54 am

OK after looking at your script and the tutorial and revising everything I managed to make it work.
thanks for helping me figure it out! T___T
Image
Charming Monsters, the webcomic Visual Novel BL game.

Post Reply

Who is online

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