infinite spawn items on inventory

Naughty Knight

New Member
Mar 28, 2021
5
1
Hello I am trying to create a action whe you pick up an item but I dont understan why it creates a couple of items every time the cursor pass over any hovered icon. I dont know why.

If somebody has any idea of how solving o changing in order to abord this, please I will be very greatfull. thanks!

Python:
init offset = -1
python:
        bpant = item("Bragas negras", imagen="icons/obj/pantMaga.png", description= "i.", cost=0)
        brandy = item("Brandy", imagen="icons/obj/brandy.png", description= "a"=0)


screen Mapa():
    imagemap:
        auto "fondos/Aldea_%s.png"
        hotspot (1519, 181, 302, 199) action Jump("Casa")
        hotspot (974, 123, 501, 434) action Jump("Guild")
        hotspot (669, 390, 176, 102) action Jump("Barn")
        hotspot (154, 324, 244, 192) action Jump("WitchH")
        hotspot (192, 536, 224, 261) action Jump("WIP")
        hotspot (1677, 687, 180, 90) action Jump("WIP")

        fixed:
            if hasMgpants == False:
                vbox:
                    xpos 500
                    ypos 500
                    imagebutton auto "pants_%s.png" action [SetVariable("hasMgpants", True), inventory.add(bpant)]  #this is what I think its causing the problem
        
            hbox:
                imagebutton auto "icons/Map_ico_%s.png" action Jump("Mapa")
                imagebutton auto "icons/Moc_ico_%s.png" action Show("Mochila")
                
screen Mochila:
    add "fondos/Inventario.png"
    modal True
    default itn = Tooltip ("   ")
    default itd = Tooltip ("   ")
    vbox:
        imagebutton auto "icons/BackArrow_%s.png" action Hide("Mochila")
    vbox:
        xalign 0.15
        yalign 0.5
        frame:
            textbutton _("[money]"):
                hovered [itn.Action("Money"), itd.Action("Current amount of money")]
                action NullAction()


    hbox :
        grid 5 4:
            # spacing 10
            xpos 810
            ypos 180
            for item in inventory.items:
                imagebutton:
                     idle item.imagen
                     xpos 20
                     ypos 5
                     hovered [itn.Action(item.name), itd.Action(item.description)]
                     action NullAction()

            for i in range( len( inventory.items ), 20 ):
                add "icons/obj/empty.png"
    frame:
        xysize (450, 40)
        xalign 0.04
        ypos 700
        text "    " + itn.value + "   "
    frame:
        xysize (450, 200)
        xalign 0.04
        ypos 750
        text  itd.value + "   "
                    
label start:
$ inventory = Inventory()
    $ money = 10
    jump Mapa
label Mapa:
    call screen Mapa
 

wurg

Active Member
Modder
Apr 19, 2018
705
1,634
If the game is adding an item when you hover over it, it would have something to do with a "hovered" statement, and not an action statement like you pointed out. Action statements only execute when the user clicks on them, hovered statements execute any time the mouse passes over the object.

The first thing I would do is comment out the hovered statements, then add them back in one at a time to see which one might be causing the issue, that way you can narrow it down.

I don't know what you are trying to do with "itn.Action(item.name)..." based upon what I see, but that could have something to do with your issue, causing an action whenever you hover over an object
 
  • Like
Reactions: Naughty Knight

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,389
15,300
If the game is adding an item when you hover over it, it would have something to do with a "hovered" statement, and not an action statement like you pointed out. Action statements only execute when the user clicks on them, hovered statements execute any time the mouse passes over the object.
In theory you are right, but here the error is more subtle than this. Look what it effectively wrote, his action line is this one:
[SetVariable("hasMgpants", True), inventory.add(bpant)]

He isn't asking Ren'py to add the item when the button will be clicked, but to do it each time the screen is displayed or refreshed. What lead to the error he get ; each time he hover one of the hotspot, the screen is refreshed and the item added to the inventory.
The line should be [SetVariable( "hadMgpants", True), Function( inventory.add, bpant )]


I don't know what you are trying to do with "itn.Action(item.name)..." based upon what I see, but that could have something to do with your issue, causing an action whenever you hover over an object
No, itd and itn are just old fashioned Tooltips, nothing more. He display them without testing if they have a value, unlike it's usually done, what is a little confusing.
 

Naughty Knight

New Member
Mar 28, 2021
5
1
Thank to both. I really appreciated!!

If the game is adding an item when you hover over it, it would have something to do with a "hovered" statement, and not an action statement like you pointed out. Action statements only execute when the user clicks on them, hovered statements execute any time the mouse passes over the object.

I don't know what you are trying to do with "itn.Action(item.name)..." based upon what I see, but that could have something to do with your issue, causing an action whenever you hover over an object
Yes the first time, I think in the same because all the objects were added whe something was hovered, but I didn't know how to solve.
And the
hovered
[itn.Action(item.name), itd.Action(item.description)]

just shows a name and a description, a simple atributes added to the items. Its a very rough way of doing it, Im not especially good at this time.

He isn't asking Ren'py to add the item when the button will be clicked, but to do it each time the screen is displayed or refreshed. What lead to the error he get ; each time he hover one of the hotspot, the screen is refreshed and the item added to the inventory.
The line should be [SetVariable( "hadMgpants", True), Function( inventory.add, bpant )]
YES!!! REALLY Thank you!!