[Solved] Fill variable with value of another variable

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
QueenBee
Newbie
Posts: 6
Joined: Mon Jul 26, 2021 10:08 am
Projects: Sweet Sweet Adventure
Organization: Honey Beer Games
Deviantart: honeybeergames
Discord: QueenBee#2285
Contact:

[Solved] Fill variable with value of another variable

#1 Post by QueenBee »

Hi, I would like to ask how to fill a newly created variable with current value of existing one.
What I am trying to achieve: I want to record an exact day (in-game one) when a player returned a book and fill a new variable with that value. I am counting them as simple numbers. No week system involved. So the next event will be available in a few days automatically.

I tried to write it in code, googled it but didn´t figure out what to do. :oops: Thanks to anyone who can help me.

QueenBee
Last edited by QueenBee on Mon Dec 06, 2021 7:08 pm, edited 1 time in total.
Creating a fantasy sandbox adult game: Game Overview.
Image

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Fill variable with value of another variable

#2 Post by Ocelot »

Assuming current_day is a simple number:

Code: Select all

$ book_returned = current_day
< < insert Rick Cook quote here > >

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Fill variable with value of another variable

#3 Post by Remix »

day_book_returned = current_day

You might want to default it as zero though, then just adjust it to match current day when the book return event occurs.
Frameworks & Scriptlets:

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Fill variable with value of another variable

#4 Post by zmook »

I hesitate to throw this in and muddy the waters since it sounds like you're very new to programming, but we ought to at least mention that there is kind of a trap lying just next door to the question you asked. It's a Python trap, nothing specifically to do with Ren'py.

The key is, Ocelot's comment about "assuming it's a simple number" is *extremely important*. If your variables are all just numbers, booleans (True/False) or strings, that's all you need to know. But if you are trying to save a copy of a *list*, *dictionary*, or *object* (instance of a Class), you need to learn the difference between "copy by value" and "copy by reference". Here's an introduction for newbies: https://www.afternerd.com/blog/python-copy-list/
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
QueenBee
Newbie
Posts: 6
Joined: Mon Jul 26, 2021 10:08 am
Projects: Sweet Sweet Adventure
Organization: Honey Beer Games
Deviantart: honeybeergames
Discord: QueenBee#2285
Contact:

Re: Fill variable with value of another variable

#5 Post by QueenBee »

Thank you all for help and kind responses. I solved it. I think that I was trying to use $ also after = assuming that othervise it will just be set to text "day'.

I will definitely read "copy by value" and "copy by reference", didn't know that there is some difference.
Creating a fantasy sandbox adult game: Game Overview.
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]