help with ui.frame and ui.imagebutton

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
Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

help with ui.frame and ui.imagebutton

#1 Post by Black_Saber »

Can I make ui.frame combining with ui.imagebutton to disappear after a certain condition?

For example, I have this code :

Code: Select all

label order:
$ ui.frame(xpos=400, ypos=350)
$ ui.imagebutton("clienta.gif", "clienta.gif", clicked=ui.returns("event_ask_a"))
$ result = ui.interact()
    if result == "event_ask_a":
        if len(carrying) == 0:
                "Where's my food?"
            else:
                "Yay, food"
                "Give him :"
                menu:
                    set dinnerchoices
                    "burger":
                        if achoice == "burger":
                            $ foods.append(achoice)
                            "Thanks"
                            $ success += 1
                            $ carrying.remove("burger")
                            hide burger
                            hide clientamini
                            $ ui.close()   
                        else:
                            "I didn't order this, stupid!!"
                            $ carrying.remove("burger")
                    "watermelon":
                        if achoice == "watermelon":
                            $ foods.append(achoice)
                            "Thanks"
                            $ success += 1
                            $ carrying.remove("watermelon")
                            hide watermelon
                            hide clientamini
                            $ ui.close()   
                        else:
                            "I didn't order this, stupid!!"
                            $ carrying.remove("watermelon")
                    "carrot":
                        if achoice == "carrot":
                            $ foods.append(achoice)
                            "Thanks"
                            $ success += 1
                            $ carrying.remove("carrot")
                            hide carrot
                            hide clientamini
                            $ ui.close()                            
                        else:
                            "I didn't order this, stupid!!"
                            $ carrying.remove("carrot")
jump order
I've tried putting the $ ui.close() there, and the game gives me the traceback

Code: Select all

Exception: ui.close() called to close the last open layer or widget.
I've tried also putting the $ ui.close() like this :

Code: Select all

$ ui.frame(xpos=400, ypos=350)
$ ui.imagebutton("clienta.gif", "clienta.gif", clicked=ui.returns("event_ask_a"))
$ result = ui.interact()
    if result == "event_ask_a":
...
...
...[the exact same code]
...
$ ui.close()
jump order
and it gives me the same traceback like above. I wanted to make the imagebutton to disappear after we finished the transaction. Need help on this.
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: help with ui.frame and ui.imagebutton

#2 Post by KimiYoriBaka »

that's not what ui.close is for. it's for if you have an ui container (like vbox or grid) that doesn't close automatically after getting the correct amount of children.

if you want something to not happen on a certain condition, just put it in an if block
example:

Code: Select all

if (not blah):
    $ ui.frame(xpos=400, ypos=350)
    $ ui.imagebutton("clienta.gif", "clienta.gif", clicked=ui.returns("event_ask_a"))
$ result = ui.interact()
this would cause the user to not to see that imagebutton if blah is true.

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#3 Post by Black_Saber »

ok, I started to improving my code from your advice.

now, for example I have this code :

Code: Select all

label testgame:
   if achoice == "none":
        $ ui.frame(xpos=400, ypos=350)
        $ ui.imagebutton("clienta.gif", "clienta.gif", clicked=ui.returns("event_ask_a"))
        $ achoice = renpy.random.choice(foods)
        show abubble at Position(xpos = 400, xanchor=2, ypos=300, yanchor=4)
        if achoice == "burger":
             show burger at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
             $ foods.remove("burger")
        if achoice == "watermelon":
             show watermelon at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
             $ foods.remove("watermelon")
  $ result = ui.interact()
    if result == "event_ask_a":
        if achoice == "carrot":
             show carrot at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
             $ foods.remove("carrot")
    ....
    .....[the exact same code]
They are, really after a click will be gone forever >.> while the random foods will be left behind..

Is it possible to make it reappear again? I want it to be something like this :

Image

then after you bring the food they requested, it will be gone like this :

Image

then after couples of second, it will appear again like the 1st pics.

I'm thinking of making it in an overlay, from showing the imagebutton, showing the randomly generated foods, and to hides it again, but looks like my knowledge still can't reach there, but I'm willing to try it anyway.

So, another question, can I do this?

Code: Select all

phyton:
    food_list = True
    def foods_show():
       for food_list(foods):
            renpy.random.choice(foods)
            if renpy.image("burger"):
                renpy.show burger at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                renpy.hide("burger")
            if renpy.image("watermelon"):
                renpy.show watermelon at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                renpy.hide("watermelon")
            if renpy.image("carrot"):
                renpy.show carrot at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                renpy.hide("watermelon")
    config.overlay_functions.append(foods_show)

label start:
$ foods = ["watermelon","carrot","burger"]
No, I haven't test the above code, yet. I just wanted to ask, can I call foods in the init phyton (which is in the upper side) even if the list of foods is explained in the label start: ?
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: help with ui.frame and ui.imagebutton

#4 Post by KimiYoriBaka »

the reason the random food isn't going away is because you didn't tell it to. if you use a show statement the image stays until you either use a hide statement (to clear a specific image) or a scene statement (to clear the screen). if you just hide the food at the time you remove it from the list, it should work.

to make the foods reappear you just need to change the condition again. Unfortunately, making them reappear again based on how much time has passed goes slightly beyond what I've experimented with, but I think you could use ui.timer to control that. If you use that though, you will probably need to to reset the ui functions after each use. This would mean just going through the loop again, but it also means that you should find a way to separate the use of renpy.random from the rest of the code.

onto the question of the overlay, you could do that, however, your code is wrong. Firstly, it's spelled "python". secondly, I'm not even sure what it is you're trying to do with the for statement there.
thirdly, if you put the random choice in the overlay, it might change every time an interaction occurs, regardless of if the interaction had anything to do with the overlay itself. if you want to use a random function with an overlay, you should make the list in a separate variable and set the one in the overlay to a random choice from the other list.

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#5 Post by Black_Saber »

Thanks for the answer, KimiYoriBaka!
KimiYoriBaka wrote:the reason the random food isn't going away is because you didn't tell it to. if you use a show statement the image stays until you either use a hide statement (to clear a specific image) or a scene statement (to clear the screen). if you just hide the food at the time you remove it from the list, it should work.
let see.. let me tweak it a bit..
KimiYoriBaka wrote:to make the foods reappear you just need to change the condition again. Unfortunately, making them reappear again based on how much time has passed goes slightly beyond what I've experimented with, but I think you could use ui.timer to control that. If you use that though, you will probably need to to reset the ui functions after each use. This would mean just going through the loop again, but it also means that you should find a way to separate the use of renpy.random from the rest of the code.
looks hard =/ well, no pain no gain. I'm gonna do what I can in the next couple of hours..
KimiYoriBaka wrote:onto the question of the overlay, you could do that, however, your code is wrong. Firstly, it's spelled "python". secondly, I'm not even sure what it is you're trying to do with the for statement there.
thirdly, if you put the random choice in the overlay, it might change every time an interaction occurs, regardless of if the interaction had anything to do with the overlay itself. if you want to use a random function with an overlay, you should make the list in a separate variable and set the one in the overlay to a random choice from the other list.
1. ah, sorry. I keep on forgot that it was python, rather than phyton >.>
2. Well, I thought I'm gonna call the list of variable from the foods array, not even sure if I'm doing it right, but oh well..
3. then there's a possibility the random food will change because of another interaction? like.. the clockticks or the analog clock or even mouse click?
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#6 Post by Black_Saber »

fuh.. dropping by and still haven't solved the right and simple way of doing it.. spend yesterday without a single things to be done...

just curious and suddenly tried using ConditionSwitch, looks good and maybe the right way to generate the random foods while separating it from the others(still, cannot make it disappear with the timer), but how to hide it?

Code: Select all

        e "test random food"
        $ randomFoods1()
        show food_list1 at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
        $ randomFoods2()
        show food_list2 at Position(xpos = 490, xanchor=2, ypos=300, yanchor=4)
        e "is it random?"
        e "Then how to hide it?"
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

pkt
Veteran
Posts: 322
Joined: Tue Jul 28, 2009 10:09 pm
Completed: I dunno
Projects: Something special
Contact:

Re: help with ui.frame and ui.imagebutton

#7 Post by pkt »

Can you post your whole game folder in a zip file?
No Active Public Renpy Projects...

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#8 Post by Black_Saber »

pkt wrote:Can you post your whole game folder in a zip file?
It's attached below.

Thanks in advance, pkt.

Regards, B_S
Attachments
cobaklikjamdanorder.rar
(124.6 KiB) Downloaded 60 times
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#9 Post by Black_Saber »

ok, using the new knowledge I got when developing the cleaning minigame, I also edited my ui in here.

Here it is :

Code: Select all

init python:
    renpy.image("clock", "Clock.png") # Short Clockhand
    renpy.image("clock_1", "Clock_1.png") # Long Clockhand
    renpy.image("clock_2", "Clock_2.png") # Clockface

    def clocktick():
        global minutes
        minutes += 1
        renpy.restart_interaction()
        return
    
    def Clocks():
         if clock: # if False - clock is hide
                ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
                ui.add("clock_2")
                # xalign and yalign can be replaced by xpos and ypos - position where the center of the clock should be
                # this segment is the one responsible for the clockface

                ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
                ui.at(RotoZoom((minutes*6), (minutes*6), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False), )
                ui.add("clock")
                # this segment is the one responsible for the short clock hand.

                ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
                ui.at(RotoZoom ((minutes*0.5), (minutes*0.5), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False))
                ui.add("clock_1")
                # this segment is the one responsible for the long clock hand.
    config.overlay_functions.append(Clocks)
    
    timegoes = True
    def timer():
        if timegoes:
            ui.timer(3.0, clocktick, repeat=True)
            ########yes, I put 3 so that it will moves a minute in 3 second.#########
            renpy.block_rollback()
    config.overlay_functions.append(timer)

label start:
$ aclick = "none"
$ achoice = "none"
[ and some other code ]

label loop:
            if aclick == "none":
                $ ui.frame(xpos=400, ypos=350)
                $ ui.imagebutton("clienta.gif", "clienta.gif", clicked=ui.returns("event_ask_a"))
            if achoice == "none":
                $ achoice = renpy.random.choice(foods)
                show abubble at Position(xpos = 400, xanchor=2, ypos=300, yanchor=4)
                if achoice == "burger":
                    show burger at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                    $ foods.remove("burger")
                if achoice == "watermelon":
                    show watermelon at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                    $ foods.remove("watermelon")
                if achoice == "carrot":
                    show carrot at Position(xpos = 420, xanchor=2, ypos=300, yanchor=4)
                    $ foods.remove("carrot")
            $ result = ui.interact()
            if result == "event_ask_a":
                if len(carrying) == 0:
                    "Where's my food?"
                    #$ minutes += 5
                else:
                    "Yay, food"
                    "Give him :"
                menu:
                    set dinnerchoices
                    "burger":
                        if achoice == "burger":
                            $ foods.append(achoice)
                            "Thanks"
                            $ success += 1
                            $ carrying.remove("burger")
                            hide burger
                            hide abubble
                            #$ minutes += 5
                            $ aclick = True
                            pause (2.0)
                            $ achoice = "none"
                            $ aclick = "none"
                        else:
                            "I didn't order this, stupid!!"
                            #$ minutes += 5
                            $ carrying.remove("burger")
At first I put $ minutes += 5 there so every action you take in that minigames, it will cost time, and when it reach the time I stated in "if minutes == number it will jump to endgame.

Now, as you noticed that I put Pause(2.0) then changed the $ achoice and $ aclick back to "none" after 2 seconds, hoping it will make a some kind of waiting time before another customer come. Using this code, I remembered about the clockticks that moved the analog clock by itself. Maybe I can use it as an actual time while we serve and delivered what customers want.

Turns out it wasn't working. The clocks will tick "IF" you didn't click at the screen at all. If you click, and click and click, they won't work.

So, is there someone can help me with this?

Regards, B_S
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: help with ui.frame and ui.imagebutton

#10 Post by Glazed Donuts »

Black_Saber: I have a question about the timer you used in your minigame.
Are you able to click around the screen and do things while the timer is still ticking in the background? I had a problem with the timer suddenly stopping and going straight to the 'endgame' as soon as you click the mouse button, which was what I was trying to avoid.

Does this script allow you to click/interact with things on the screen without stopping the clock due to the mouse being clicked?

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#11 Post by Black_Saber »

Glazed Donuts wrote:Black_Saber: I have a question about the timer you used in your minigame.
Are you able to click around the screen and do things while the timer is still ticking in the background? I had a problem with the timer suddenly stopping and going straight to the 'endgame' as soon as you click the mouse button, which was what I was trying to avoid.

Does this script allow you to click/interact with things on the screen without stopping the clock due to the mouse being clicked?
Actually, after tweaking a bit last night, it's working. Well, still sometimes it didn't tick (looks like it was the effect of my Pause(1.0), but overall, it's working.

BUT

after I changed it into

Code: Select all

timegoes = True
    def timer():
        if timegoes:
            ui.timer(1.0, clocktick, repeat=True)
            ########Look, I changed into 1, so it will moves a minute after 1 seconds.#########
            renpy.block_rollback()
    config.overlay_functions.append(timer)
Actually, you can put any number there. It's depends on your transaction.

In my case, because it's just :

1. click the chef
2. choose which food
3. choose another food
4. click the customers
5. gives the requested food

The 5 action above can be done within 3 second at most, so if I put 3, or 4, it won't moved, because of the Pause(1.0) that stops the timer. (or it's because another things happen? I don't know. The only one I think of is the Pause(1.0).

Basically I put 1 and 2, and it's work even if I click in the ground stage(without making any interaction to the chef or the customers). And even if I talking with one of them, the clock will still ticking.

In the start, I define the minute :

Code: Select all

    $ minutes = 420
And in the end of minigame, I put

Code: Select all

            if minutes >= 480:
                jump endgame
So when the clocks either reach 480, or more, it will automatically jumps into endgame.

p.s: don't forget to remove $ minutes += number :D
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: help with ui.frame and ui.imagebutton

#12 Post by Glazed Donuts »

Hmm... I'm confused. Where is the code in which the timer automatically goes and ignores the mouse clicks? Also, is the keyboard ignored while the timer is going, as well?

Black_Saber
Regular
Posts: 74
Joined: Wed Jul 14, 2010 4:56 am
Completed: cafe minigame
Projects: Beach Restaurant
Location: Indonesia
Contact:

Re: help with ui.frame and ui.imagebutton

#13 Post by Black_Saber »

Hmm I'm making a mistake when explaining up there so I will explain it in more detail below:

1. the clock won't tick if you repeatedly click the imagebutton (in this situation, the chef and the customers)
2. the clock will tick if you're in the choice menu (for example when you wanted to choose which food you want to get from the chef, or when you're choose which food in your hand that you wanted to give to the customers)
3. the clock will tick if you repeatedly clicked on the screen or just a click
4. the clock won't tick if you put Pause(number of second). After the number of second is done, the clock will tick again.
5. the clock won't tick if you're clicked the customer or the chef in the first time. After a brief second, the clock will tick again.
"*cackle*cackle*! In short, it's all about cleverly using the gaps between jobs to play. If it goes too far, it can turn to laziness. However, people only become mature when they learn to balance work with pleasure. Simply put, if all you care about is work all the time, you're not fully mature." - Gaap (Umineko no Naku Koro ni)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Ocelot