Page 1 of 1

[SOLVED] Point and Click + Timer question!

Posted: Fri Dec 07, 2018 7:55 pm
by Eirrir
Hello everyone! I'm working on a game that has some point-and-click elements and would like to be able to add a timed feature for it as well so that players will have a limited time to pick and choose what they want to check out. I'm using an imagemap with hotspots that change the cursor when hovered over and, when pressed on, will jump to other labels. Those labels will call the screen again until every hotspot is checked.

When I "show screen countdown," everything works like it should except that the cursor doesn't change when hovering over the hotspots, which is very crucial! I was wondering if there is some way to tweak the code I have to allow the cursor-hover to work when the timer is shown. I'm not even sure why it's not working the way it should. Any help is greatly appreciated!

Please take a look at the code I have for this:

Code: Select all

define config.mouse = { 'default' : [ ('cursor.png', 0, 0)], 'imagemap' : [ ('qm.png', 0, 0)], 'camera' : [ ('cam_cursor.png', 0, 0)] }

Code: Select all

screen countdown:
    zorder 99
    timer 0.01 repeat True action If(time > 0, true=SetVariable('time', time - 0.01), false=[Hide('countdown'), Jump(timer_jump)])
    style_group "pref"
    bar value time range timer_range style "timerbar"

Code: Select all

screen lh_click: 
    on "hide" action Hide("displayTextScreen")

    imagemap:
        ground "lh_zoom"
        hover  "lh_zoom"
        hotspot (306, 161, 269, 252) clicked [Return("value"), Jump("look_computers")] mouse "imagemap" #hovered [ Play ("test_two", "sfx/camera_beep.ogg")]
        hotspot (109, 481, 255, 173) clicked [Return("value"), Jump("look_table")] mouse "imagemap" #hovered [ Play ("test_two", "sfx/camera_beep.ogg")]
        hotspot (304, 0, 374, 74) clicked [Return("value"), Jump("look_lights")] mouse "imagemap" #hovered [ Play ("test_two", "sfx/camera_beep.ogg")]
        hotspot (725, 124, 333, 181) clicked [Return("value"), Jump("look_windows")] mouse "imagemap" #hovered [ Play ("test_two", "sfx/camera_beep.ogg")]

Code: Select all

    $ time = 4
    $ timer_range = 4
    $ timer_jump = 'scene1_pt1'
    show screen countdown
    call screen lh_click
label look_table:
    $ check_table = True
    "Blah"
    if check_computers == True and check_windows == True and check_table == True and check_lights == True:
        jump scene1_pt1
    else:
        call screen lh_click
label look_lights:
    $ check_lights = True
    "Blah"
    if check_computers == True and check_windows == True and check_table == True and check_lights == True:
        jump scene1_pt1
    else:
        call screen lh_click
label look_computers:
    $ check_computers = True
    "Blah"
    if check_computers == True and check_windows == True and check_table == True and check_lights == True:
        jump scene1_pt1
    else:
        call screen lh_click
label look_windows:
    $ check_windows = True
    "blah"
    if check_computers == True and check_windows == True and check_table == True and check_lights == True:
        jump scene1_pt1
    else:
        call screen lh_click
label scene1_pt1:
    scene lh
    hide screen countdown

Re: Point and Click + Timer question!

Posted: Sun Dec 09, 2018 9:04 pm
by philat
Unsure why the timer would interfere with the cursor, but try using AnimatedValue instead of calling the timer so often.

Re: Point and Click + Timer question!

Posted: Mon Dec 10, 2018 12:48 pm
by Eirrir
philat wrote: Sun Dec 09, 2018 9:04 pm Unsure why the timer would interfere with the cursor, but try using AnimatedValue instead of calling the timer so often.
Thank you very much for your suggestion! I tried what you said with this new timer code:

Code: Select all

screen countdown:
    zorder 99
    timer time repeat False action [Hide('countdown'), Jump(timer_jump)]
    #style_group "pref"
    bar value AnimatedValue(0, time, time, time) xmaximum 200 xalign 0.5 yalign 0.05
And it indeed fixed the mouse hover issue, but a new problem cropped up. Now, whenever I click on something, the timer would reset to the full time, even though I want the timer to continue the time left off before I clicked the hotspot. Sorry if the way I just explained it is confusing, haha!

Re: Point and Click + Timer question!

Posted: Mon Dec 10, 2018 1:13 pm
by Per K Grok
Eirrir wrote: Mon Dec 10, 2018 12:48 pm And it indeed fixed the mouse hover issue, but a new problem cropped up. Now, whenever I click on something, the timer would reset to the full time, even though I want the timer to continue the time left off before I clicked the hotspot.
I have a different approach to looping a timer.

Code: Select all

label timer:
    $ renpy.pause(delay=0.2, hard=True)
    if vKoll==1:
        jump firstKoll
     elif vKoll==2:
        jump secondKoll
        
label firstKoll:
    [--- do stuff ---] 
    jump timer
It gives the possibility to run 0.2 second loops in which you can update stuff.

I don't know if this is useful for your situation, but it has worked very well for me doing point and click stuff.

Re: Point and Click + Timer question!

Posted: Mon Dec 10, 2018 2:36 pm
by Eirrir
Thanks for the help, everyone! I tinkered with code a bit and found that the solution is actually pretty simple. I just changed the timer value in my original code from 0.01 to 0.05.

Code: Select all

screen countdown:
    zorder 99
    timer 0.05 repeat True action If(time > 0, true=SetVariable('time', time - 0.05), false=[Hide('countdown'), Jump(timer_jump)])
    style_group "pref"
    bar value time range timer_range style "timerbar"
This has been solved :)

Re: [SOLVED] Point and Click + Timer question!

Posted: Mon Dec 10, 2018 8:50 pm
by philat
Some suggestions. There is zero reason that clicking should reset the timer unless you have something that is manually hiding/reshowing the countdown screen.

Code: Select all

screen countdown:
    zorder 99
    timer time action [Hide('countdown'), Jump(timer_jump)]
    bar value AnimatedValue(0, time, time, time) xmaximum 200 xalign 0.5 yalign 0.05

screen lh_click: 

    imagemap:
        ground # image here
        idle # image here
        hover  # image here
        hotspot (306, 161, 269, 252) action Jump("look_computers") mouse "imagemap" # doesn't seem like you're doing anything with the Return, so you don't need it
        hotspot (109, 481, 255, 173) action Jump("look_table") mouse "imagemap"
        hotspot (304, 0, 374, 74) action Jump("look_lights") mouse "imagemap"
        hotspot (725, 124, 333, 181) action Jump("look_windows") mouse "imagemap"

label start:
    show screen countdown
    call screen lh_click

label look_table:
    $ check_table = True
    "Blah"
    jump scene1_pt1_check

label look_lights:
    $ check_lights = True
    "Blah"
    jump scene1_pt1_check

label look_computers:
    $ check_computers = True
    "Blah"
    jump scene1_pt1_check

label look_windows:
    $ check_windows = True
    "blah"
    jump scene1_pt1_check

label scene1_pt1_check:
    if not (check_computers and check_windows and check_table and check_lights):
        call screen lh_click

label scene1_pt1:
    hide screen countdown
    "Time up / all searched"