[SOLVED] How best to implement a game loop and still have buttons etc.

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
VideoGameVet
Newbie
Posts: 24
Joined: Fri Jun 07, 2019 1:03 pm
Skype: william_volk
Contact:

[SOLVED] How best to implement a game loop and still have buttons etc.

#1 Post by VideoGameVet »

So I need to have a game loop. In this case, the game is about traveling so the loop would be cover a journey over several days. The game has to tell the user their progress and if any events happen (random) let them know about it. The user needs to be able to stop traveling to engage in activities as they wish.

Ideally, I'd have a map, with a symbol moving along the path and also display the status of the player and trip (miles/km to destination and other stats).

I'm familiar with doing this "back in the day" with 'C', but I am a noob in Ren'Py, so I'm just looking for the best way to do it in Ren'Py.

Perhaps the 'timer' function with jump implementing the loop in a screen?

I want to be able to use Ren'Py's text display stuff for events etc., so I'd rather not just do a pure Python solution.

Thank you.
Last edited by VideoGameVet on Thu Jun 20, 2019 1:41 pm, edited 1 time in total.
"A delayed game is eventually good, but a rushed game is forever bad."
- Shigeru Miyamoto

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: How best to implement a game loop and still have buttons etc.

#2 Post by Per K Grok »

VideoGameVet wrote: Tue Jun 18, 2019 2:24 pm So I need to have a game loop. In this case, the game is about traveling so the loop would be cover a journey over several days. The game has to tell the user their progress and if any events happen (random) let them know about it. The user needs to be able to stop traveling to engage in activities as they wish.

Ideally, I'd have a map, with a symbol moving along the path and also display the status of the player and trip (miles/km to destination and other stats).

I'm familiar with doing this "back in the day" with 'C', but I am a noob in Ren'Py, so I'm just looking for the best way to do it in Ren'Py.

Perhaps the 'timer' function with jump implementing the loop in a screen?

I want to be able to use Ren'Py's text display stuff for events etc., so I'd rather not just do a pure Python solution.

Thank you.

I don't claim to to know the best way of doing this or that. With that in mind,

You can use a timer on repeat in a screen to add to a variable. You could the use the value of that variable to decide how far the ship has travelled and such.

A simple code for a counter like that could be.

Code: Select all


default nomb=0

screen update():
    text str(nomb)
    timer 0.2 repeat True action SetVariable("nomb", nomb+1)

label start:
    show screen update
    $ renpy.pause(hard=True)


Something I sometimes do is to add a loop in the script. Something like this.

Code: Select all


label looper:
    $ renpy.pause(delay=0.2, hard=True)
 
    -----  do some stuff -----

    jump looper

But what I think you really want to look into when going outside the regular renpy box, so to speak, is Creator-defined displayables.
https://www.renpy.org/doc/html/udd.html

Maybe not for this task, but if I read you correctly, sooner or later you will want to go there. :)

User avatar
VideoGameVet
Newbie
Posts: 24
Joined: Fri Jun 07, 2019 1:03 pm
Skype: william_volk
Contact:

Re: How best to implement a game loop and still have buttons etc.

#3 Post by VideoGameVet »

Thank you for that. Nice simple approach.

I ended up with this solution, thanks to some help ...

Code: Select all


init python:
    def increment_distance():
        # make sure the value is saved
        store.distance += 1
        renpy.notify("Distance {}".format(distance))
        if (distance == 15):
            renpy.call("arrived")
        # here is where we will check for random events, eventually

screen travel_menu():
    frame:
        xalign 0.4 ypos 30
        hbox:
            spacing 50
            vbox:
                spacing 15
                textbutton "Travel" action [Notify("Traveling"),SetVariable("traveling",True)]
                textbutton "Talk to People" action [Notify("Talking"),Return()]
            vbox:
                spacing 15
                textbutton "Shop" action Notify("Shopping")
                textbutton "Rest" action SetVariable("traveling",False)

    if traveling:
        timer 1.0 action Function(increment_distance) repeat True
"A delayed game is eventually good, but a rushed game is forever bad."
- Shigeru Miyamoto

Post Reply

Who is online

Users browsing this forum: Bing [Bot]