Script running in background

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
Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Script running in background

#1 Post by Exiscoming »

Not sure if this is possible, but I don't think this is too hard of a question.
How do I make a script that continues playing / repeating while the rest of the game continues as normal?
I'd basically like to add something as simple as this:

Code: Select all

default guardDirection = 1			# 1 is looking left, 2 is looking right

layeredimage guard:
	if guardDirection == 1:
		"guard.png"
	if guardDirection == 2:
		"guard.png"
		xzoom -1				# Flip image

label guardScript:
	show guard
	pause 2.0
	$ guardDirection = 2
	pause 2.0
	$ guardDirection = 1
	jump guardScript
Obviously, the above code creates an infinite loop. But it it possible to do something like this?

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Script running in background

#2 Post by strayerror »

You could use a transform to do this:

Code: Select all

layeredimage guard:
    "guard.png"

transform guard_anim:
    pause 2.0
    xzoom -1
    pause 2.0
    xzoom 1
    repeat

label guardScript:
    show guard at guard_anim
    'end'
    return

Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Script running in background

#3 Post by Exiscoming »

Hi there stray, thanks for your suggestion!
So unfortunately that won't work exactly as I hoped. It's important that I can update variables.
That way I can check with an if statement to see if the guard is currently looking at the player.
For example:

Code: Select all

if guardDirection == 1:
	"You managed to sneak by."
else:
	"You've been caught!"
You can't put variable changes inside of a transform, right?

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Script running in background

#4 Post by strayerror »

Aha, in that case, I'm not sure if it's the best way, but you could use a custom transform to publish the guard's direction to a variable:

Code: Select all

layeredimage guard:
    'guard.png'

default guard_direction = 1

init python:
    def guard_sweep(trans, st, at):
        global guard_direction # publish direction globally
        guard_direction = trans.xzoom = -guard_direction # reverse direction
        return 2 # seconds until next flip

label guardScript:
    show guard:
        function guard_sweep
    'We need to sneak past, just say when!'
    if guard_direction == 1:
        'You managed to sneak by.'
    else:
        "You've been caught!"
    'end'
    return

Post Reply

Who is online

Users browsing this forum: Andredron