Affecting user choice using item

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
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Affecting user choice using item

#1 Post by wulfsaga » Sun Feb 08, 2009 9:32 am

I want to create VN using Phoenix wright style which use item to affect the story line. So i though i use gift command will be effective... but what i got is a lot of error.
here is sample "

menu:
"Check the computer":
$ gift = "key"
m"looks like somekind of password, but who put password in big computer screen?"
jump choice1
"Open the door":
m "lets try it"
jump door

label door:
m "is it locked?"
menu:
"input password"
if gift = "key"
m "looks like it FAIL"
jump FAIL :(
is $ gift command only usefull for dialog only?
i am confused, can anyone tell me how to make command where the user get an item and then use it on some object?
Image

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Affecting user choice using item

#2 Post by JQuartz » Sun Feb 08, 2009 10:13 am

Doing it in the following way would work:

Code: Select all

menu:
    "Check the computer":
        $ gift = "key"
        m"looks like somekind of password, but who put password in big computer screen?"
        jump choice1
    "Open the door":
        m "lets try it"
        jump door

label door:
    m "is it locked?"
    menu:
        "input password":
            if gift == "key":
                m "It worked!"
            else:
                m "looks like it FAIL"
                jump FAIL :(
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

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: Affecting user choice using item

#3 Post by akemicchi » Sun Feb 08, 2009 10:27 am

Ahaha... Me, I don't exactly understand what it is you want to happen. ^^; Could you describe it in more detail, please? And I only know of Phoenix Wright being a linear story, so I don't understand how it would affect the storyline, save for the progression... If you want dialogue to change, you shohuld use JQuartz' example. C:
i am confused, can anyone tell me how to make command where the user get an item and then use it on some object?
Do you mean-- if the player has a certain item, they can open a new menu choice? You can use variables in menus, too, if you want! :o

Code: Select all

label look_through_drawers:
    $ important_item = "key"
    "I rummage through the drawers. Inside, I find a gold key, with oddly-shaped prongs."
    return
label look_through_ref:
    $ important_item = "cheese"
    "I open the refrigerator door. Inside, a slice of cheese."
    "It could be useful..."
    return
label do_you_have_key:
    menu:
        "Hmmm. There's an oddly-shaped keyhole here..."
        "Use the key." if important == "key":
            "I put the key inside. A perfect fit. I turn the knob, and head inside."
            jump scene2
        "Put the cheese in the keyhole!!" if important_item == "cheese":
            "Ingenious. Because this is the most absurd choice, it must be the right answer!!"
            "I take out the slice of cheese, and stuff it into the keyhole. It oozes through and ultimately jams the keyhole with all its cheesy goodness."
            ".... Nothing happens."
            "Well, a lot of good that did. I'm permanently stuck in this room and now I have nothing to eat."
            jump gameover
        "I'll come back later.":
            jump search
Similarly, you can just use True or False and assign multiple variables for each item, or even use renpy.input instead of just toggling variables, if you want the player to present an actual password. :D Example:

Code: Select all

menu:
    "Check the computer":
        $ gift = "key"
        m "looks like somekind of password, but who put password in big computer screen?"
        jump choice1
    "Open the door":
        m "lets try it"
        jump door

label door:
    m "is it locked?"
    $ use = renpy.input("What should I use to open the door?", "None", length=20)
    if gift == "key" and use == 'key':
        m "It worked!"
    if use == 'key':
        m "I don't have a key!!"
        return
    else:
        m "looks like it FAIL"
        jump FAIL :(
Here, you need to find the key to be able to use it. xD Is something like this what you want?

User avatar
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Re: Affecting user choice using item

#4 Post by wulfsaga » Sun Feb 08, 2009 10:55 am

wow thx for the advice, this is my first programming experience so it so confusing.....
@JQuartz : it work great!
now

@ akemicchi : whew bit complicated, but i will try your method! :D
Image

User avatar
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Re: Affecting user choice using item

#5 Post by wulfsaga » Wed Feb 11, 2009 12:06 am

okay i already find game system that may work using all above, now my other question is:
Assuming we got 'Key' and we want to see what item we have in inventory box, which function do we use?
I want to create a button that will pop up inventory box and the key picture appear on the box, and if you click it you use it. (too complex?)
i see http://www.renpy.org/wiki/renpy/doc/ref ... _Functions but failed to understand it... @_@
Image

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Affecting user choice using item

#6 Post by JQuartz » Wed Feb 11, 2009 12:46 am

Yeah ui is a bit complicated...Anyway here's an example of the inventory box (as usual, this method is not the best method but it works):

Code: Select all

init:
    $ key=True
init python:
    
    def inventory_button():
        ui.textbutton('See inventory', clicked=ui.callsinnewcontext('inventory'))
    config.overlay_functions.append(inventory_button)
        
label inventory:
    $ ui.vbox(xpos=.5)
    if key:
        $ ui.imagebutton("key.png","key_hover.png",clicked=ui.jumps('use_key'))
    $ ui.textbutton('Return to game', clicked=ui.jumps('return_to_game'))
    $ ui.close()
    $ ui.interact()
label use_key:
    $ used_key=True
    "Or whatever effect using the key has..."
    return
label return_to_game:
    return
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Re: Affecting user choice using item

#7 Post by wulfsaga » Wed Feb 11, 2009 6:05 am

uuh...looks difficult..
thanks, ill try it! :mrgreen:
Image

User avatar
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Re: Affecting user choice using item

#8 Post by wulfsaga » Tue Feb 17, 2009 2:44 am

okay so i already know how to make item show description.
init:
$ key=True
$ ask2 = False
init python:
def inventory_button():
ui.textbutton('See inventory', clicked=ui.callsinnewcontext('inventory'))
config.overlay_functions.append(inventory_button)

label inventory:
$ ui.vbox(xpos=.5)
if key:
$ ui.imagebutton("key.bmp","key2.bmp",clicked=ui.jumps('use_key'))
$ ui.textbutton('Return to game', clicked=ui.jumps('return_to_game'))
$ ui.close()
$ ui.interact()
label use_key:
$ used_key=True
$ gift = "key2"
"A key to the past and future. What is the your unlucky number?"
return
label return_to_game:
return
Now i want to know how to USE it on some object like 'key' on a 'Door'. Example there is a locked door, i got a key, i open inventory and click the key, and..viola! it opens!
so far i failed to implement it using $ used_key=True... :(
Image

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Affecting user choice using item

#9 Post by JQuartz » Tue Feb 17, 2009 3:40 am

Well one way uses jump to prevent progress unless used_key=True like so:

Code: Select all

label locked_door:
    "The door won't open because it's locked."
    if not used_key:
        "Maybe if I had the key..."
        jump locked_door
    "The door opened! The room is totally filled with erotic VN! No wonder they wanted to keep the door locked..."
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
wulfsaga
Regular
Posts: 29
Joined: Thu Feb 05, 2009 9:40 am
Contact:

Re: Affecting user choice using item

#10 Post by wulfsaga » Mon Feb 23, 2009 6:34 am

i got another problem, i already create inventory button, however the button is appear at starting of game and i want to hide it when cutscene appear. I confused, is the 'hide' command can be used on python? :cry: :cry:
Image

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Affecting user choice using item

#11 Post by JQuartz » Mon Feb 23, 2009 7:06 am

wulfsaga wrote:i want to hide it when cutscene appear. I confused, is the 'hide' command can be used on python?
I don't know if hide is usable on python but if you want to hide overlay, just put a if above the button code like so:

Code: Select all

init python:
   
    def inventory_button():
        if show_inventory_button:
            ui.textbutton('See inventory', clicked=ui.callsinnewcontext('inventory'))
    config.overlay_functions.append(inventory_button)
And when you want the button to disappear just set show_inventory_button=None. If you want it to appear then set show_inventory_button=True. Also put one show_inventory_button=True (or None) in the init otherwise the game will crash. You should use True though since you want the button to appear since the beginning of the game.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], pronehouse, staffofmagic