Affection Points Animation [Solved]

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
K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Affection Points Animation [Solved]

#1 Post by K0torisan »

Hi! In my game, endings are based on the standard affection point system, and I have an animation attached to choices that helps players understand when they've picked a "good" or "bad" answer.

I want to declare the animation at the top of my game so that I don't have to type out the animation after every choice, and instead I can write one statement.

The problem I'm running into is that I don't know how to code this when there are two images in the animation, and I want only one of them to move. To give you an idea of what it looks like, there is a diamond next to the characters name and an arrow beside the diamond. If points go up, the arrow slides out. If points go down, the arrow slides down.

Right now, I have this code set up at each choice: (This is for an increase in points)

Code: Select all

	show character_affection_base:
            xalign 0.29 yalign .74
        show affection_arrow:
            xalign .29 yalign .74
            linear 1.0 xalign .33
        with dissolve
        hide character_affection_base
        hide affection_arrow
        with dissolve
It's needlessly bulky after every single choice, and I'd like to simplify it... but I'm doing something wrong when I try to clean up the code. Thanks for any help!
Last edited by K0torisan on Thu Jul 26, 2018 5:55 pm, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Affection Points Animation

#2 Post by Imperf3kt »

Put the code in its own label, and use "call" when you need it. You can also optimise that by turning it into ATL, you're mostly there already. Although, I don't see anything in your code that moves or animates.

As to which image to use, you just need one condition to check.

For example:

Code: Select all

default affection_points = 0
default affection_action = "None"

label affection:
    if affection_acton = up:
        show character_affection_base:
            xalign 0.29 yalign .74
        show affection_arrow:
            xalign .29 yalign .74
            linear 1.0 xalign .33
        with dissolve
        hide character_affection_base
        hide affection_arrow
        with dissolve
    elif affection_action = down:
        # your code here

    return

label start:
    "Lets give you some affection."
    $ affection_points += 1
    $ affection_action = "up"
    call affection
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Affection Points Animation

#3 Post by K0torisan »

I'm getting an error message. :cry:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1287, in script call
    call alex_affection_animation
  File "game/script.rpy", line 637, in script
    if alex_affection_action = up:
SyntaxError: invalid syntax (script.rpy, line 637)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 1287, in script call
    call alex_affection_animation
  File "game/script.rpy", line 637, in script
    if alex_affection_action = "up":
  File "/Users/kotorisan/Desktop/renpy-6.99.12.4-sdk/renpy/ast.py", line 1729, in execute
    if renpy.python.py_eval(condition):
  File "/Users/kotorisan/Desktop/renpy-6.99.12.4-sdk/renpy/python.py", line 1941, in py_eval
    code = py_compile(code, 'eval')
  File "/Users/kotorisan/Desktop/renpy-6.99.12.4-sdk/renpy/python.py", line 674, in py_compile
    raise e
SyntaxError: invalid syntax (script.rpy, line 637)

More information that might be helpful - there are different "bases" for each character, so I have to define everything differently for each character. I also already have persistent variables that are in the format [character name]_affection, so I changed the names of the variables.
Here is what I entered:

Code: Select all

default alex_affection_action = "None"

label alex_affection_animation:
    if alex_affection_action = up:
        show alex_affection_base:
            xalign 0.29 yalign .74
        show affection_arrow:
            xalign .29 yalign .74
            linear 1.0 xalign .33
        with dissolve
        hide alex_affection_base
        hide affection_arrow
        with dissolve
    elif alex_affection_action = down:
        show alex_affection_base:
            xalign 0.29 yalign .74
        show affection_arrow:
            xalign .33 yalign .74
            linear 1.0 xalign .29
        with dissolve
        hide alex_affection_base
        hide affection_arrow
        with dissolve
    return 
I took off the "default affection_points = 0" because I already have a variable defined like that, although it comes after the start label... so that might cause some issues?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Affection Points Animation

#4 Post by Imperf3kt »

Regarding the error message - I forgot to wrap quotation around the variable "

Regarding defining after the start label, yes it will cause issues with loading. Defaulting a variable before the start label prepares it before the game starts, but doing it after the start label only happens once - if a player loads a game that has been saved beyond that point, it Ren'Py won't know you declared the variable and will throw errors stating it is undefined.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Affection Points Animation

#5 Post by K0torisan »

Wait - can you be more specific about where to put the quotations? I wrapped them around the "alex_affection_action" and the "up/down" (and combinations of either), and I'm still getting Syntaxerror messages.

Also, moved the character_affection variables.

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Affection Points Animation

#6 Post by MaydohMaydoh »

Alternatively you could probably make a transform.

Code: Select all

transform affection_up():
	align (0.29, 0.74) alpha 0.0
	on show:
		parallel:
			linear 0.5 alpha 1.0
		parallel:
			linear 1.0 xalign 0.33
	on hide:
		linear 0.5 alpha 0.0
and then use it with whatever image you want to apply it too.

Code: Select all

show affection_arrow at affection_up
hide affection_arrow
As for the syntax error in the previous code. Up and down should be have quotations and for the if statement it should be == not =

Code: Select all

if alex_affection_action == "up":

K0torisan
Regular
Posts: 26
Joined: Fri Feb 16, 2018 10:21 pm
Contact:

Re: Affection Points Animation

#7 Post by K0torisan »

Got it! Thanks for all the help!

Post Reply

Who is online

Users browsing this forum: pockatuck