[Solved] SetVariable to copy a variable value to another variable's value?

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
yon
Regular
Posts: 153
Joined: Tue Sep 09, 2014 5:09 pm
Projects: YDSP
Location: United States
Contact:

[Solved] SetVariable to copy a variable value to another variable's value?

#1 Post by yon » Tue Aug 16, 2022 5:18 pm

Hi all,

I'm trying to copy a variable's value to a persistent variable at the end of a game playthrough.

Basically, the process is this:
  • Take value from variable
  • Copy variable to separate persistent variable
  • Start new game
  • Persistent variable's value is copied to non-persistent variable
  • That variable is now the same value it was when you finished the game
I'm doing this instead of just using the persistent variable the entire time to prevent the possibility of rewinding the game and passing through the variable value raising parts of the code multiple times, and essentially being able to "grind" that without doing it properly. That is to say, I only want the variable change to be carried over at the end of a game to NG+. How can I achieve that?

I've tried, but I'm somehow misunderstanding things.

Code: Select all

python:
    action SetVariable("persistent.v_mind_end", v_mind)
    action SetVariable("persistent.v_heart_end", v_heart)
    action SetVariable("persistent.v_soul_end", v_soul)
    action SetVariable("persistent.v_guts_end", v_guts)
    action SetVariable("persistent.v_quin_end", v_quin)
This keeps giving me a syntax error, but I don't understand what I'm doing wrong. Can I not use another variable in the "value" field of SetVariable? That's kind of the whole point of what I'm trying to achieve.
Last edited by yon on Wed Aug 17, 2022 3:56 am, edited 1 time in total.

User avatar
m_from_space
Veteran
Posts: 303
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: SetVariable to copy a variable value to another variable's value?

#2 Post by m_from_space » Wed Aug 17, 2022 12:21 am

The keyword python is the starting point of a block of python code. But you use renpy (screen related) code in your example.

Code: Select all

python:
    persistent.v_mind_end = v_mind
    ...

User avatar
yon
Regular
Posts: 153
Joined: Tue Sep 09, 2014 5:09 pm
Projects: YDSP
Location: United States
Contact:

Re: SetVariable to copy a variable value to another variable's value?

#3 Post by yon » Wed Aug 17, 2022 3:55 am

That looks like it works! Thank you!

Post Reply

Who is online

Users browsing this forum: _ticlock_