Simulate a mouse click

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.
Message
Author
User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Simulate a mouse click

#1 Post by LiveTurkey »

Is there any way to simulate a single mouse click?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#2 Post by trooper6 »

Can you give more context of what you want to do and why you want to do it?

Mouse click to do what? Advance text? Press a button?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#3 Post by LiveTurkey »

trooper6 wrote:Can you give more context of what you want to do and why you want to do it?

Mouse click to do what? Advance text? Press a button?

Yeah advance text. Not simulate a button.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#4 Post by trooper6 »

What triggers the text to advance? Does it advance after a certain amount of time? After something happens?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#5 Post by LiveTurkey »

trooper6 wrote:What triggers the text to advance? Does it advance after a certain amount of time? After something happens?
Well here's the whole problem.
I have this code. It's to give a character an item from your backpack. However there's a weird bug.

Code: Select all

label give:
    show screen backpack    
    $ renpy.pause()
    #correctly waits for an item to be chosen
    $ speakerId = (speaker + "_id")
    if (itemGiven == getattr(store, speakerId)):
        #incorrectly waits again for a mouse click before changing the expression. 
        show expression ( speaker + " happy")
        $ renpy.say(getattr(store, speaker[0]), "Good Item")
    elif (itemGiven == "NULL"):
        #incorrectly waits again for a mouse click before changing the expression. 
        show expression ( speaker + " surprised")
        $ renpy.say (getattr(store, speaker[0]), "No item")
    else:
        #incorrectly waits again for a mouse click before changing the expression. 
        show expression ( speaker + " disgusted")
        $ renpy.say (getattr(store, speaker[0]), "Bad item")
    jump expression location
"show screen backpack" works and shows your inventory with all of it's items. Then I "$ renpy.pause()" so the game wont continue until the user either selects an item from the backpack or selects no item and closes the backpack.

However after an item (or no item is selected) there seems to be a second pause before the expression is shown. That why I wanted to simulate a mouse click. To get rid of this second pause.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#6 Post by trooper6 »

What does your screen backpack look like?
Do you plan on having the user only press one button on that screen?
If there are any functions you have attached to that screen, what are those functions?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#7 Post by LiveTurkey »

trooper6 wrote:What does your screen backpack look like?
Do you plan on having the user only press one button on that screen?
If there are any functions you have attached to that screen, what are those functions?
My backpack screen is pretty simple

It's mostly just this

Code: Select all

Imagebutton:
        idle "backgrounds/transparent.png"
        action [Hide ("backpack"), SetVariable("itemGiven", noItem)]
    add "backgrounds/backpack.png"    
    $ inv_items = inventory.items
for Item in inv_items:
    imagebutton: 
            idle pic 
            hover h_pic 
            xpos a 
            ypos b 
            action [SetVariable("itemGiven", Item.type), Hide("item_desc"), Hide("item_name"), Hide("backpack")] 
            hovered [Show(("item_name"), Item = i_name), Show(("item_desc"), Item = i_name)]  
            unhovered [Hide("item_desc"), Hide("item_name")]
Yes I plan on having the user only press one button on that screen.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#8 Post by trooper6 »

That isn't the full screen code it doesn't seem...and there seems to be strangeness with your indentation. Could you post the entire screen code? I want to know if it is modal and the other details of it.

Anyway, If you only plan on having the user press one button, get rid of all the hide stuff in your actions and just call the screen rather than show it. Then you shouldn't need to do the pause at all.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#9 Post by LiveTurkey »

trooper6 wrote:That isn't the full screen code it doesn't seem...and there seems to be strangeness with your indentation. Could you post the entire screen code? I want to know if it is modal and the other details of it.
That's pretty much the whole screen code. It isn't modal or anything.

trooper6 wrote: Anyway, If you only plan on having the user press one button, get rid of all the hide stuff in your actions and just call the screen rather than show it. Then you shouldn't need to do the pause at all.
If I do call instead of show then the pause becomes permanent and there is no way to advance the game after selecting an item, even by clicking.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#10 Post by trooper6 »

LiveTurkey wrote: That's pretty much the whole screen code. It isn't modal or anything.

Code: Select all

Imagebutton:
        idle "backgrounds/transparent.png"
        action [Hide ("backpack"), SetVariable("itemGiven", noItem)]
    add "backgrounds/backpack.png"    
    $ inv_items = inventory.items
for Item in inv_items:
    imagebutton: 
            idle pic 
            hover h_pic 
            xpos a 
            ypos b 
            action [SetVariable("itemGiven", Item.type), Hide("item_desc"), Hide("item_name"), Hide("backpack")] 
            hovered [Show(("item_name"), Item = i_name), Show(("item_desc"), Item = i_name)]  
            unhovered [Hide("item_desc"), Hide("item_name")]
This is your entire screen code? Because then I don't even know how this is working. Are you calling your screen Imagebutton? It seems like the screen is called "backpack," but nowhere do I see the line where you define the screen. Assuming the line is there but you didn't provide it for some reason, then Imagebutton is supposed to actually be an imagebutton? But if so, it shouldn't be capitalized. And what is it supposed to be doing? Also your indentation is messed up.

This is not what a screen definition looks like. Examples of what screen definitions look like can be found in the screens.rpy file in any new project.

You keep asking for answers to small problems, but without giving the larger overview. I suspect you have a problem with the larger overview. I can give you the quick answer to this question:
LiveTurkey wrote:If I do call instead of show then the pause becomes permanent and there is no way to advance the game after selecting an item, even by clicking.
Which is: add Return() to your button actions.

But I feel like there are larger problems with your screen design that should be addressed. I would like to see the *entire* screen definition with annotations of what you want each section to do, to maybe help you end up with something that will work better, more elegantly, and not cause unexpected negative consequences.

In case you don't know what a complete screen definition looks like it would include the line:

Code: Select all

screen backpack():
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#11 Post by LiveTurkey »

trooper6 wrote:
But I feel like there are larger problems with your screen design that should be addressed. I would like to see the *entire* screen definition with annotations of what you want each section to do, to maybe help you end up with something that will work better, more elegantly, and not cause unexpected negative consequences.
I cleaned it up a bit, here is the full backpack screen but like I said it's pretty much what I already posted.

Code: Select all

screen item_desc (Item):
    $ description = Item.description
    text description pos 205, 525
    
screen item_name (Item):
    $ name = Item.name
    text name pos 205, 500

screen backpack:
    $ noItem = "NULL"
    
    imagebutton:
        idle "backgrounds/transparent.png"
        action [Hide ("backpack"), SetVariable("itemGiven", noItem)]
    add "backgrounds/backpack.png"    
    $ amountOfColumns = 3
    $ columnPosition = 0
    for Item in inventory.items:
        $ i_name = Item
        imagebutton: 
            idle Item.image 
            hover Item.hoverImage 
            xpos 430+((columnPosition%amountOfColumns)*200)
            ypos 230+((columnPosition//amountOfColumns)*200)
            action [SetVariable("itemGiven", Item.type), Hide("item_desc"), Hide("item_name"), Hide("backpack")] 
            hovered [Show(("item_name"), Item = i_name), Show(("item_desc"), Item = i_name)]  
            unhovered [Hide("item_desc"), Hide("item_name")]
        $ columnPosition += 1
Last edited by LiveTurkey on Wed May 24, 2017 4:25 pm, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#12 Post by trooper6 »

Let me ask some questions.
*Can you explain the first image button? What is backgrounds/transparent.png? Is it actually just a blank/transparent image with nothing on it? Are you just wanting so that if the player presses anywhere on the screen except for the buttons you want it to close? It this button currently working for you? Do you actually need it?
*If you want columns...why aren't you using an hbox? Is there a reason you aren't using it or did you just not know about hboxes?

I'm going to fix this screen for you, I just need a bit more detail about what this is supposed to look like.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#13 Post by LiveTurkey »

trooper6 wrote:Let me ask some questions.
*Can you explain the first image button? What is backgrounds/transparent.png? Is it actually just a blank/transparent image with nothing on it? Are you just wanting so that if the player presses anywhere on the screen except for the buttons you want it to close? It this button currently working for you? Do you actually need it?
*If you want columns...why aren't you using an hbox? Is there a reason you aren't using it or did you just not know about hboxes?

I'm going to fix this screen for you, I just need a bit more detail about what this is supposed to look like.
I edited the code a bit more and edited my post. The first image button is a completely transparent 1920*1080 image and yes it's purpose is that if the player presses anywhere on the screen except for the buttons, the backpack closes. It is currently working as intended. I didn't use an hbox because I want my backpack screen to actually look like a backpack not those stylized boxes. And the columns and rows implementation works great, I don't think that's the problem.

And BTW, changing it to call screen instead of show screen and adding Return() seemed to fix my problem. Thanks!

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Simulate a mouse click

#14 Post by trooper6 »

Do you have a max number of items that can be in the backpack at any given time?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
LiveTurkey
Regular
Posts: 109
Joined: Tue Dec 27, 2016 10:50 pm
Location: Brooklyn
Contact:

Re: Simulate a mouse click

#15 Post by LiveTurkey »

trooper6 wrote:Do you have a max number of items that can be in the backpack at any given time?
I'm not sure about that honestly. Currently there is no max limit but if I add too many item it starts going off the screen. So I have to either put a cap on the number of items or make my inventory scrollable. Neither have been implemented and I'm not sure which I'm going to pick.

I don't know if you read my edit to the last post but I fixed the problem (thanks your help)

Changing it to call screen instead of show screen and adding Return() fixed the problem. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users