setting a variable to have same value as 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
MarkW
Newbie
Posts: 4
Joined: Sun Oct 21, 2012 4:21 am
Contact:

setting a variable to have same value as another variable?

#1 Post by MarkW » Sun Oct 21, 2012 4:37 am

Hi All,

New user, just got a quick coding question. It it possible to tell Ren'Py to make a variable have the same value as another variable? (Both of which need to change at various points in the game.)
I'm writing a Politics Sim where I want at times the Active Minister(One whose dealing with the current issue) to be the same person as the Agriculture Minister. The dialogue calls are then based on this. The game I'm writing has lots of possibilities based on the ministers you pick so this is pretty essential for the game to work.

So far I've tried:

# The game starts here.
label start:
$ agr = 0
$ active = 0

then later, tried both of the following:

$ active = agr()
$ active = $ agr

getting back:
File "game\script.rpy", line 748: invalid syntax
active = $ agr

I know this probably seems simple, but I spent a few hours on the reference/manual and looking through posts here and couldn't find it. I'm also new to programming ;) Anyone know the answer? Thanks.

Mark

User avatar
Anima
Veteran
Posts: 448
Joined: Wed Nov 18, 2009 11:17 am
Completed: Loren
Projects: PS2
Location: Germany
Contact:

Re: setting a variable to have same value as another variabl

#2 Post by Anima » Sun Oct 21, 2012 4:55 am

It's:

Code: Select all

$ active = agr
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: setting a variable to have same value as another variabl

#3 Post by Ayutac » Sun Oct 21, 2012 4:57 am

@ Anima: wouldn't that just copy the value?

@ MarkW
Normal variables in python do not work that way. When you work with objects the "=" will copy the reference so all fields of the two objects variables will be synchronized (to be more exact, they are the same). Seems like the simpliest solution to me. Maybe you want to learn some python before coding further?

Also thanks for you introduction, it was very appealing.
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

User avatar
Anima
Veteran
Posts: 448
Joined: Wed Nov 18, 2009 11:17 am
Completed: Loren
Projects: PS2
Location: Germany
Contact:

Re: setting a variable to have same value as another variabl

#4 Post by Anima » Sun Oct 21, 2012 8:21 am

No it simply sets the pointer to the same memory address as the other variable. It's not copied.
That's exactly the behaviour we want in this case.
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III

MarkW
Newbie
Posts: 4
Joined: Sun Oct 21, 2012 4:21 am
Contact:

Re: setting a variable to have same value as another variabl

#5 Post by MarkW » Sun Oct 21, 2012 8:56 am

@Anima - Thanks, tried it and It's all working now. ;)

@Ayutac - Cheers for the Python link - having had a look at what I need to do, probably will need some more coding skills.

Cheers for the quick response, guys ;)

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: setting a variable to have same value as another variabl

#6 Post by Ayutac » Sun Oct 21, 2012 10:35 am

Anima wrote:No it simply sets the pointer to the same memory address as the other variable. It's not copied.
That's exactly the behaviour we want in this case.
That behaviour does not amuse me. I'll have a look at this later on, it could be a very dangerous source for errors in my project.... So, thanks for the hint!


And oh nuts! Seems I gave you the link to a German python tutorial. My bad, guess you have to look for some in your language...
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_