[Bug] python function as imagebutton action, firing multiple times

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
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

[Bug] python function as imagebutton action, firing multiple times

#1 Post by ISAWHIM »

EDIT: Updated follow-up post. Will make a better "functional" test-sample, if needed. My example below is specific to my program and does not function alone, without the other code.

I had previously used an action of Jump("somelocation"), as the action for an image-button. However, to reduce repeating duplicate code, I created a python function instead.

Originally, within the function, I had a renpy.jump("somelocation"), which just caused errors that could not be correctly located. (The errors were all pointing to some unrelated "menu", in another file, and something about not using close transient...)

I removed the jump from the function, and returned it to the image-button, after the call to the function. (Instead of it going to unique locations. They all now return to one universal location, with that menu.) The menu is just a stopping point, where you select some action to do at the location you are at.

So, the issue is this... The function is simply as follows...

Code: Select all

init python:
    def fMoveTo(loc):
        global YOU
        if YOU.L.find("home") != -1 and loc.find("home") == -1:
            YOU.L = loc
            fTimeChange(15)
        else:
            YOU.L = loc
            fTimeChange(0)
This is intended to function, by checking for the word "home" within the "loc" call, compared to the players actual location "YOU.L". If home is in both, there is no time progression. If home is in one, but not the other, it adds 15 minutes.

The code for the time-progression works fine. Nothing has changed there. Same with the jump-location, which holds the menu, asking what you want to do next.

However, now, with that function added, the game is in hyper-mouse mode. Every click on the screen seems to trigger 1-5 clicks, noted by the time progression being 15 minutes to 1-hour and 15-min.

The other buggy part, is it keeps returning to a section that was never clicked. (There is a second page with another button, that it keeps going to. Though it is never clicked or even "shown" on the screen.)

SideNavB "town clothingstore", (which is on a screen that isn't loaded), is what every button randomly, about 95% of the time, loads, when clicking on any other image-button, while on the SideNavA screen.

Code: Select all

screen sideNavA:
    zorder 10
    fixed:
        imagebutton auto "btn/loc home %s.jpg" xpos 1564 ypos 210 action [Hide("sideNavA"), Show("sideNavB"), SetVariable("groupLocB", 7)]
        imagebutton auto "btn/loc yourbedroom %s.jpg" xpos 1564 ypos 318 action [SetVariable("groupLocA", 0), SelectedIf(groupLocA == 0), SetVariable("groupLocB", 7), fMoveTo("home yourbedroom"), Jump("TimeLoop")]
        imagebutton auto "btn/loc sparebedroom %s.jpg" xpos 1564 ypos 426 action [SetVariable("groupLocA", 1), SelectedIf(groupLocA == 1), SetVariable("groupLocB", 7), fMoveTo("home sparebedroom"), Jump("TimeLoop")]
        imagebutton auto "btn/loc masterbedroom %s.jpg" xpos 1564 ypos 534 action [SetVariable("groupLocA", 2), SelectedIf(groupLocA == 2), SetVariable("groupLocB", 7), fMoveTo("home masterbedroom"), Jump("TimeLoop")]
        imagebutton auto "btn/loc bathroom %s.jpg" xpos 1564 ypos 642 action [SetVariable("groupLocA", 3), SelectedIf(groupLocA == 3), SetVariable("groupLocB", 7), fMoveTo("home bathroom"), Jump("TimeLoop")]
        imagebutton auto "btn/loc lounge %s.jpg" xpos 1564 ypos 750 action [SetVariable("groupLocA", 4), SelectedIf(groupLocA == 4), SetVariable("groupLocB", 7), fMoveTo("home lounge"), Jump("TimeLoop")]
        imagebutton auto "btn/loc terrace %s.jpg" xpos 1564 ypos 858 action [SetVariable("groupLocA", 5), SelectedIf(groupLocA == 5), SetVariable("groupLocB", 7), fMoveTo("home terrace"), Jump("TimeLoop")]
        imagebutton auto "btn/loc poolyard %s.jpg" xpos 1564 ypos 966 action [SetVariable("groupLocA", 6), SelectedIf(groupLocA == 6), SetVariable("groupLocB", 7), fMoveTo("home poolyard"), Jump("TimeLoop")]

screen sideNavB:
    zorder 10
    fixed:
        imagebutton auto "btn/loc town %s.jpg" xpos 1564 ypos 210 action [Hide("sideNavB"), Show("sideNavA")]
        imagebutton auto "btn/loc clothingstore %s.jpg" xpos 1564 ypos 318 action [SetVariable("groupLocB", 0), SelectedIf(groupLocB == 0), SetVariable("groupLocA", 7), fMoveTo("town clothingstore"), Jump("TimeLoop")]
        add "btn/loc work.jpg" xpos 1564 ypos 426
        add "btn/loc away.jpg" xpos 1564 ypos 534
It jumps 30 min, in the game, just after loading, when it should be doing (0) for time advance... hitting any keyboard button, makes it advance too... even ESC and 2nd-mouse button...

Thus, it is completely bugging-out.
Last edited by ISAWHIM on Thu Nov 16, 2017 9:09 am, edited 1 time in total.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: python function as imagebutton action, firing multiple times

#2 Post by ISAWHIM »

Okay, this morning, I tried the code again. I thought it may be just that RenPy was running too long, and other stuff running may have been messing with it.

It got worse when running alone. (Seems that now it is running faster and not yielding to all the other stuff which was previously on the screen.)

I am assuming that this is a full bug. (Not sure how to move this to the "bugs" page.)

This is what it seems to be doing. It is a function, trying to "return", and it does... Back to every single button at once, or in succession, triggering every instance as the button "refreshes" (drawing). It will refresh the screen with other locations that are not any of the ones actually selected. The final "exit" is that last button, clothing shop", which is on the unseen screen. Thus, why I usually see that screen as the end-result.

However, I have no idea why it ALSO triggers when not clicking on any button at all, or why it triggers on key-presses and ESC. Unless the fault is ALSO in the refresh, for the "Click to continue", or in the key/mouse callback.

In any event, it seems that we can't use functions within an imagebutton as the action. Since it seems to trigger for each occurrence with that same function, in every imagebutton, even when not clicking the actual imagebutton.

Why it is triggering the (15 min) interval, is because after hitting each "home" location of (0-min), it is hitting the last location 1-8 times... Now adding up to 2-hours of time-passage. (Once for each button-state check? and again for mouse-up and mouse-down? That is roughly 8 times... idle, hover, selected-idle, selected-hover. Which are the four auto %s states in those buttons...)

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: [Bug] python function as imagebutton action, firing multiple times

#3 Post by RicharDann »

This happened to me before, and I think it's because functions from screens need to be called using Function screen action. So something like this:

Code: Select all

imagebutton auto "my_button_%s.jpg" action Function(fMoveTo, "home yourbedroom")
Last edited by RicharDann on Thu Nov 16, 2017 9:50 am, edited 2 times in total.
The most important step is always the next one.

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: [Bug] python function as imagebutton action, firing multiple times

#4 Post by Remix »

fMoveTo("home yourbedroom") is not a valid button action, it should be wrapped in a Function call, as should any action that runs a function.

Function( fMoveTo, "home yourbedroom" )
Frameworks & Scriptlets:

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: [Bug] python function as imagebutton action, firing multiple times

#5 Post by ISAWHIM »

Remix wrote: Thu Nov 16, 2017 9:46 am fMoveTo("home yourbedroom") is not a valid button action, it should be wrapped in a Function call, as should any action that runs a function.

Function( fMoveTo, "home yourbedroom" )
Acording to the help file, it is... valid button action
Along with these actions, an action may be a function that does not take any arguments. The function is called when the action is invoked. If the action returns a value, then the value is returned from an interaction.
Wording translation, as it is written in the help-file...
"Along with these" = In addition to the following actions working... An actual "function" (python code), will ALSO suffice as an "Action".

It doesn't say "Python functions are not a valid action. You must use a special function-call, stated below, formatted as a Function()."

Those suggestions did appease the issue. Thank-you. Both of you.

However, if it can't be made to work, it should be throwing an error. That condition is easy to find and intercept as being invalid, before attempting to run. (Kindly stating as the error-reply, that Function() should be used.)

Still, it is a bug. It shouldn't destroy the whole program like that.

I assume that a "python function" may have worked, when tested in just a singular instance, thus, it was assumed that "python functions also work, as actions"... However, that is not true here. Might be the AUTO state, which is messing that up. I have not tried it on a literal statement for an imagebutton. (Mentioned so it can be researched for debugging, for interception as an "error", or avoidance, or for actual working code to function.)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]