Characters and Variables [More or Less Solved]

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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Characters and Variables [More or Less Solved]

#1 Post by trooper6 »

Hello All!

My code currently works, but I want to make it better. Also, I haven't yet put sprites in the game...and I think what I currently have might be irritating when it is time to code the sprites in. So, I'm here asking to ask a question.

Here is the set up.

I have a Barber character. This barber character is a slow talker. Sometimes, when he is slow talking, the player can interrupt the barber, sometimes he can't. (There is one other variation, but that isn't important for the moment).

So I've created a callback function, the point of it is to turn off the CTC button while the barber is talking, and for variation 0 turn on my interrupt button, for variation 1 you don't, and then check to see if the user interrupted the barber..this is more or less what it looks like:

Code: Select all

    def arrow(event, inter=False, **kwargs):
        global can_interrupt
        global can_cont
        global interrupts
        global icheck
        global base_int
        if inter == 0:
            if event == "show" or event == "begin":
                base_int = interrupts
                can_interrupt = True
                can_cont = False
            if event == "slow_done" or event == "end":
                can_interrupt = False
                can_cont = True
                if interrupts > base_int:
                    icheck = True
                else:
                    icheck = False
                renpy.restart_interaction()
        if inter == 1:
            if event == "show" or event == "begin":
                can_cont = False
            if event == "slow_done" or event == "end":
                can_cont = True
                renpy.restart_interaction()
Okay, so I then defined to separate barber characters, one interruptible, one not. This looks like this:

Code: Select all

define b = Character('[barb_name]', color="#994411", what_color="#FFFFCC", 
    what_slow_cps=20, what_slow_abortable=False, callback=arrow, cb_inter=1)
define bI = Character('[barb_name]', color="#994411", what_color="#FFFFCC", 
    what_slow_cps=20, what_slow_abortable=False, callback=arrow, cb_inter=0)
In play it looks like this:

Code: Select all

    b "I thought so. I'm from the country myself." #Barber Friendly

    c "Really? What part?" #Customer C4 Curious

    bI "{=narr}(He mixes the lather in a small mug--){/=narr}{fast} Oh, that would 
        be difficult to say. You see, I've moved around so much that I'm neither 
        a Southerner nor a Northerner. I'm just an American....Though I lived 
        in a little town near Savannah for a year." #Barber Friendly, transitioning to Barber Observing
So, I'm moving onto that space where I'm going to start doing all the graphics stuff...and I want to play with live composite and all of that. And I realized, it might not be good to have four different barbers. (my callback actually has four variations, even though I only showed 2).

Now the question. Is it possible to have only 1 barber character, let's say with the cb_inter variable defaulted to 1 (which is the no interrupt version), but for some say statements change the cb_inter variable to 0?

I know there are conditionswitches used for graphics...but can something like that be used for by cb_inter variable...or just variables in general?

I mean can I do something like:

Code: Select all

b "Here I am talking slowly and you can't interrupt me."
b "{cb_inter=1}Here I am talking slowly and you can interrupt me.{/cb_inter}"
Well, I tried that out and I can't actually do that because cb_inter isn't a text tag. But is there some other way I can change variables?
Last edited by trooper6 on Sun Jan 25, 2015 3:38 am, edited 1 time in total.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
akemicchi
Veteran
Posts: 465
Joined: Mon Dec 31, 2007 11:22 pm
Projects: Magicians of Delphine, Panaderia: Ensaimada, SweetTooth!, XOXO Droplets
Deviantart: littlebabyshoes
Contact:

Re: Characters and Variables

#2 Post by akemicchi »

In your callback, why don't you just use a global variable "inter" to check if you can interrupt or not? That way, all you'd have to do to make the barber interruptable is:

Code: Select all

$ inter = 0
b "Here I am talking slowly and you can't interrupt me."
$ inter = 1
b "Here I am talking slowly and you can interrupt me."

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Characters and Variables

#3 Post by trooper6 »

akemicchi wrote:In your callback, why don't you just use a global variable "inter" to check if you can interrupt or not? That way, all you'd have to do to make the barber interruptable is:

Code: Select all

$ inter = 0
b "Here I am talking slowly and you can't interrupt me."
$ inter = 1
b "Here I am talking slowly and you can interrupt me."
*smacks forhead*

Well that is an obvious, easy, and elegant solution! Thank you!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Characters and Variables [Sort of Solved]

#4 Post by trooper6 »

In case anyone is interested, this is what I actually did in the end.

I started with akemicci's suggestion, but then pondered if I could be even better...mostly because I'm still interested in the idea of keyword arguments perhaps being more efficient.

So I have my barber character:

Code: Select all

define barb = Character('[barb_name]', color="#994411", what_color="#FFFFCC", 
    what_slow_cps=20, what_slow_abortable=False, callback=arrow)
Then inspired by this page here that xela pointed out:
http://www.renpy.org/doc/html/statement ... l#dialogue

I decided to make a Python version of the character that deals with the now global inter variable that the callback uses.

Code: Select all

    def b(what, i=1, **kwargs):
        global inter
        inter = i
        barb(what, **kwargs)
        inter = 1
So this means that rather than this:

Code: Select all

$ inter = 1
b "Here I am talking slowly and you can't interrupt me."
$ inter = 0
b "Here I am talking slowly and you can interrupt me."
I can now do this:

Code: Select all

b "Here I am talking slowly and you can't interrupt me."
$b ("Here I am talking slowly and you can interrupt me.", i=0)
This has saved me quite a few lines of code. The only irritating thing is that I have to break up long lines in a less smooth way. I mean it's the difference between:

Code: Select all

    n "The scene is a humble barber shop. At the center are two barber chairs 
       facing a mirror and washstand off to the right. The concrete walls are 
       plastered with the usual advertisements. At the rear, up two steps, a door 
       leads to the busy streets of Chicago. A clock on the left wall indicates five to three."
and

Code: Select all

    $b ("{=narr}(He mixes the lather in a small mug--){/=narr}{fast} Oh, that would "+
        "be difficult to say. You see, I've moved around so much that I'm neither "+
        "a Southerner nor a Northerner. I'm just an American....Though I lived "+
        "in a little town near Savannah for a year.", i=0) #Barber Friendly, transitioning to Barber Observing
But I suppose it is still worth it. And I've also learned a bit more about coding! So it is all good.

Anyhow, I suppose what I've learned is that if I want to use variables, I need to do it through invoking a Python version of character.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users