Screen Jumps To Label (callinnewcontext?)

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
TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Screen Jumps To Label (callinnewcontext?)

#1 Post by TheChatotMaestro »

Scenario:
-you are playing the game, clicking through text and reading it as normal
-from a small button above the textbox, you open the inventory, a screen with a list of textbuttons generated from the list of your items
-from the inventory, you click a textbutton open this screen showing details about the placholderitem item

Code: Select all

screen placeholderitem: 
    frame:
        has vbox
        text "blah blah there's a lot of text here"
        textbutton "Use" action ???() #uses the item (button only present if the item in question is usable, if it isn't I just won't put the button here)
        textbutton "Drop" action ???() #deletes ONE of the item from the inventory (button only present if the item in question is droppable, if it isn't I just won't put the button here)
        textbutton "Back" action Return() #goes back
Is there any way to make one of these actions on the textbuttons a "jump"?

The use button will first determine whether or not the item can be used where you are, and then do one of two things. If the item cannot be used, it will call another screen, which will simply say 'sorry you can't use that here' and then have a button to go back to the item screen. However, if it CAN be used, it will jump to a label of visual novely texty stuff, not a screen.
How would I go about the calculations for 'does x = y and a = b"? I'm pretty sure that can't be done in a screen, so would I have to jump then call a screen? Can I even jump from a screen? Can I calculate them in a screen?

The drop button will subtract one from your total amount of the item. Every item exists as a sort of dictionary of properties- with an item name, an item type, and an amount. When you click the drop button, it will edit the amount property to be one less than it was before, and then exit the whole inventory screen to whatever you were doing before you opened the inventory (hence me describing how you get to this screen, as you might need to know that), because if you have dropped all of that item (say you only had one and you got rid of it), and the amount of that item now equaled 0, it would be removed from your list of items, and that item would then no longer show up in the list of buttons on your inventory screen.
Same problems as above, lots of "set x to y if a = b" stuff involved, which I can do just fine, but I don't know where to put them and how to start it off.

I've been looking all over, but can't find any documentation on a way to do this- however, from what I can decipher from others' forum posts, it looks like there's a command called "callsinnewcontext()" might be what I need. Is this the action I am looking for? (Warning: I haven't tested any of this yet because all of these screens are buried under a whoooole lot of read-this-opening-dialogue-before-it-lets-you-do-anything, so it's very hard to just boot up my project and noodle around with, so I'm working on taking all this code out and putting it in its own project for testing and whatnot. I might just be talking nonsense. Plz forgive me if i am)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#2 Post by xavimat »

Some thoughts:
- Do you know how to use classes in python? It's very convenient for what you want to do.
- calls in new context is a very advanced feature, I'm sure it's not what you need.
- I have a question on the logic of your game. You say that the player can USE an item if certain conditions are met. But can they also NOT USE that item and the story continues anyway? That's important because Jump will lose track of the point where your story was. Let's say that the player uses that item and then the game Jumps to the label where the item is used ("label of visual novely texty stuff"). What next? How the game knows how/where to go on? I'm not saying that this is not correct, but you need to think very well the flow of the game.

I'm going to try an example and post here again.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#3 Post by TheChatotMaestro »

-Will research, thank u!
-okidoki
-I'm mostly going to be using this in character interactions, where there's a menu and you select 'give gift'. Then it sets a bunch of variables to make only gift-type items usable, and on the next textbubble, you use the item. The character reacts, heart goes up, and then it jumps back to the interaction menu. If you have nothing in your inventory to give, it'll tell you. If you don't give an item, and instead just click to go to the next text, it jumps back to the interaction menu, like nothing ever happened.
If there's ever a time where a specific item is required to proceed, you will 100% always have the key item you need, and it will jump to a looping text that says 'use item now' or whatever (its own label that jumps back to itself), and you'll have to use it to go to the next section. That won't happen often, it'll probably be a special or dramatic moment.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#4 Post by xavimat »

Maybe this can give you some ideas. I've used a class for the Items. Your description of items ("Every item exists as a sort of dictionary of properties- with an item name, an item type, and an amount") is pretty much what objects are, but you can add functions inside them. You could, for example, put a function "usable" inside the class to check if it's usable according to the variables of your game.

Code: Select all

default inventory = []
default usable_type = None
init python:
    class Item:
        def __init__(self, name, label, info, type):
            self.name = name
            self.label = label
            self.info = info
            self.type = type
            self.amount = 1

        def add(self, amount=1):
            self.amount += amount
        def drop(self, amount=1):
            self.amount = max(0, self.amount-amount)

screen inventory_button():
    frame:
        textbutton "Inventory" action Show("inventory_screen")
screen inventory_screen():
    modal True    
    default selected_item = None
    default notusable = False

    add "#000b"

    frame:
        xalign .2
        has vbox
        for i in [i for i in inventory if i.amount > 0]:
            textbutton i.name action SetScreenVariable("selected_item", i)
            text "Amount: [i.amount]"
            null height 20
        textbutton "Close" action Hide("inventory_screen")

    if selected_item:
        frame:
            xalign .8
            has vbox
            text selected_item.info
            if selected_item.type == usable_type:
                textbutton "Use":
                    action [
                        Hide("inventory_screen"),
                        Function(selected_item.drop),
                        Jump(selected_item.label)
                        ]
            else:
                textbutton "Use" action SetScreenVariable("notusable",True)
            textbutton "Drop" action Function(selected_item.drop)

    if notusable:
        add "#000b"
        frame:
            align (.5, .5)
            padding (40,40)
            has vbox
            text "Sorry you can't use that here." xalign .5
            textbutton "Close":
                xalign 1.0
                action SetScreenVariable("notusable",False)

label start:
    $ flowers = Item("Flowers", "use_flowers", "Flowers are pretty.", "gift")
    $ diamond = Item("Diamond", "use_diamond", "Girl's best friend.", "gift")
    $ ring = Item("Ring", "use_ring", "It's round.", "gift")
    $ phone = Item("Phone", "use_phone", "It goes 'riiing'.", "tool")
    $ inventory = [flowers, diamond, ring, phone]
    show screen inventory_button
    jump date
label date:
    $ usable_type = "gift"
    "Girl" "Are you sure you don't have anything for me?"
    "'Girl' stares at me."
    jump after_date
label use_flowers:
    "Girl" "I'm sorry, I'm allergic."
    # $ heart down...
    jump after_date
label use_diamond:
    "Girl" "For me????"
    # $ heart up
    jump after_date
label use_ring:
    " Girl" "It's too soon for that..."
    # heart stays
    jump after_date
label after_date:
    $ usable_type = None
    "The story goes on..."
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#5 Post by TheChatotMaestro »

I was using someone else's inventory system before, and having an out-of-nowhere problem with always getting an item not defined error no matter what I did, even though it'd been working fine for ages. I'll try this out, though, and let you know what happens.

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#6 Post by TheChatotMaestro »

Update: the code is working spectacularly on its own! I've been able to figure out almost everything I need to do, from different situations producing different results to using my own button to bring up the menu (and scooching the inventory screen over so it's not awkwardly floating there since the button's moved) to duplicating and tweaking it for the sake of character profiles. I had to change what the close button did so the textbox would reappear, but other than that, there weren't any problems! If anyone else's looking for a good inventory system, this works absolutely fantastically! Thank you so so so much omg

TheChatotMaestro
Regular
Posts: 91
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#7 Post by TheChatotMaestro »

Ugh. So super sorry to triple post, but I'm having trouble using the add and drop functions on their own- like, just in between text boxes. Trying "ring.add" or "function(ring.add)" or anything just says 'expected statement'. Is there any way to use these correctly, or are they just for the drop button?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Screen Jumps To Label (callinnewcontext?)

#8 Post by xavimat »

What do you mean "text boxes"?
If you are talking about dialogue in labels, just use the $ symbol to tell renpy that, in that line, you are writing python code and not renpy code:

Code: Select all

label whatever:
    "I have a phone"
    $ phone.drop()
    "Oh, I have it no more..."
BUT: Be aware that my code was simply a quick example. The inventory should be another class, with methods to access items.
For example, in my Item class, simply creating an item it has an amount of 1, that's too simple for actual use, where maybe you want to create items without amount.
Also, the code $ phone.drop() does not check if the item is actually in the inventory list.
This is not a full inventory system, only some code to give you ideas.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: No registered users