Item action

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
KarloPan
Newbie
Posts: 14
Joined: Thu Jun 22, 2017 8:16 pm
Contact:

Item action

#1 Post by KarloPan »

Hello there,

I just want to ask if it is Possible to link an class with an action to an item
i have my Item class

Code: Select all

    class Item(object):
        def __init__ (self, name, weight, actions=[]):
            self.name = name
            self.weight = weight
            self.actions = []
i have my Inventory screen

Code: Select all

screen inventory_screen():
    modal False
    hbox align (.5,.01) spacing 20:
        textbutton "Close Inventory" action [ Hide("inventory_screen"), Show("inventory_button"),]
    frame:
        background Solid ("#00000090")
        align (1.0, 0.5)
        
        side "c r":
            area (0, 0, 320, 1080)
            
            viewport id "vp":
                draggable True

                vbox:
                    for item in backpack.inventory:
                        textbutton ("[item.item.name], [item.amount]") action [item.item.actions]


            vbar value YScrollValue("vp")
and i defined my item

Code: Select all

        paper = Item('Paper', 1, actions=['item_choice_2'])
and i defined item_choice_2

Code: Select all

    menu item_choice_2:
        "Bye":
            "Bye"
        "Hi":
            "Hallo"
Renpy starts and it doesn't give me an error... it just don't work... and i would like to know why xD
i can click on my item but nothing happen :/
Would be great if someone had a solution xD
Thanks :3
Karlo

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Item action

#2 Post by Remix »

Perhaps it would be best if you said what you are trying to achieve as there are several errors within your shown code...

item.item.name -- item has no attribute item
item.amount -- item has no attribute amount (just weight)
item.item.actions-- item has no attribute item

Even with those fixed, a textbutton action of 'item_choice_2' would do nothing... is it meant to show the menu, hide the menu, move the menu, select the first choice... how is ren'py meant to guess?

Read this page on actions
Frameworks & Scriptlets:

KarloPan
Newbie
Posts: 14
Joined: Thu Jun 22, 2017 8:16 pm
Contact:

Re: Item action

#3 Post by KarloPan »

there are no errors xD i just do not post the full code xD
sry :s
because i do not think in the other code parts is the error... but ok xD again sorry :S

Code: Select all

    class Item(object):
        def __init__ (self, name, weight, actions=[]):
            self.name = name
            self.weight = weight
            self.actions = []
    
    class InvItem(object):
        def __init__(self, item, amount, actions=[]):
            self.item = item
            self.amount = amount
            self.actions = []
i used the inventory system from "Milkymalk" viewtopic.php?f=51&t=44730&p=458992&hil ... ry#p458992
item.item.name -- item has no attribute item
item.amount -- item has no attribute amount (just weight)
item.item.actions-- item has no attribute item

about these three things.. i got no error, and it works,

this is Milkymalks Description why item.item.name works
So if you want the name, you have to use item.item.name for that (the first 'item' is what you called it in the iteration loop, the second 'item' is the Item object contained in it alongside the amount, and inside that object there is the name).
the thing what should happen is that an menu should pop up where you can choose between different options like "Use" or "Eat"
Like here http://i.imgur.com/IVy2aS7.jpg

First we thought it would work with "Expressions" in a menu... but sadly it doesn't work
we tried it like this

Code: Select all

$ cola = Item('Cola', 5, actions={'use': 'drink'})
$ paper = Item('Paper', 1, actions={'drop': 'rip up'})

menu Choice:
    cola.actions['use']: ## this is the key point, I don't know if you can use expressions here; if it gives an error, try adding 'expression' in front of it
        ## script
    cola.actions['drop']:
        ## script
i also tried to put 'Expression' in front of it but it doesn't work...

So i asked here :D
Sry again for the missed part :(

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot]