function... function?

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.
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: function... function?

#31 Post by Kia »

can you tell me the name of this screen please?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: function... function?

#32 Post by xela »

Code: Select all

screen tim1:
        timer 0.1 repeat True action If(prcnt > 99,true=SetVariable('prcnt', 0),false=SetVariable('prcnt', prcnt+1))
        timer 0.1 repeat True action [SetVariable('prcnt', rndmzr(prcnt1)), SetVariable('prcnt2', rndmzr(prcnt2)), SetVariable('prcnt3', rndmzr(prcnt3))]
        timer 0.1 repeat True action Execute(rndmzr)
I am not sure what you're trying to do here but rhis:

Code: Select all

timer 0.1 repeat True action Execute(rndmzr)
is correct.

Code: Select all

timer 0.1 repeat True action [SetVariable('prcnt', rndmzr(prcnt1)), SetVariable('prcnt2', rndmzr(prcnt2)), SetVariable('prcnt3', rndmzr(prcnt3))]
This is not.

Besides calling a function that takes no arguments with an argument, you're doing it directly on screen without a wrapper and that's wrong by definition.
Like what we're doing? Support us at:
Image

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: function... function?

#33 Post by Kia »

I thinks you got a little confused here. that line has # at it's beginning and that means it's a comment so it gets ignored in compiling. (I kept it because it was working)

I Isolated your Execute in a new project and it's not working either.

Code: Select all

define prcnt = 100

screen testis:
    text "{size=100}[prcnt]" xalign 0.5 yalign 0.82
    
screen tim1:
    timer 0.1 repeat True action Execute(rndmzr)

init python:
    class Execute(Action):
        def __init__(self, func, *args, **kwargs):
            self.func = func
            self.args = args
            self.kwargs = kwargs
        
        def __call__(self):
            self.func(*self.args, **self.kwargs)
            
    import random
    
    def rndmzr():
        prcnt=store.prcnt
        if prcnt> 99:
            prcnt= 0
        else:
            b = random.randint(-1, 3)
            prcnt += b


label start:

    "You've created a new Ren'Py game."
    show screen testis
    show screen tim1
    "Once you add a story, pictures, and music, you can release it to the world!"

    return

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: function... function?

#34 Post by xela »

Everything's working.

You just don't have anything that would update the screens because this isn't a proper game. It's counting/executing just like it's supposed to. If you want to see the progress, add renpy.restart_interaction() to your function.
Like what we're doing? Support us at:
Image

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: function... function?

#35 Post by Kia »

still nothing happening. I'll go back to my last working code and try to use curry ^_^
thanks

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: function... function?

#36 Post by xela »

Code: Select all

define x = 100

screen testing:
    timer 0.1 repeat True action Execute(my_func)
    text "{size=100}[x]" align(0.5, 0.5)

init python:
    class Execute(Action):
        def __init__(self, func, *args, **kwargs):
            self.func = func
            self.args = args
            self.kwargs = kwargs
       
        def __call__(self):
            self.func(*self.args, **self.kwargs)
           
    def my_func():
        if store.x > 99:
            store.x = 0
        else:
            store.x += renpy.random.randint(-1, 3)
        renpy.restart_interaction()    

label start:
    show screen testing
    
    "You've created a new Ren'Py game."
    "Once you add a story, pictures, and music, you can release it to the world!"
    
    return
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: function... function?

#37 Post by xela »

b3vad wrote:

Code: Select all

init python:
    def rndmzr():
        prcnt=store.prcnt
        if prcnt> 99:
            prcnt= 0
        else:
            b = random.randint(-1, 3)
            prcnt += b
This was poor advice from my part:

Code: Select all

    def my_func():
        x = store.x
        if x > 99:
            x = 0
        else:
            x += renpy.random.randint(-1, 3)
        store.x = x
would work but decent python however would be:

Code: Select all

    def my_func():
        global x
        if x > 99:
            x = 0
        else:
            x += renpy.random.randint(-1, 3)
Last edited by xela on Tue Aug 12, 2014 9:25 am, edited 1 time in total.
Like what we're doing? Support us at:
Image

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: function... function?

#38 Post by Kia »

yes the global did the trick ^_^ thank you xela

Post Reply

Who is online

Users browsing this forum: Donmai, Google [Bot]