Setting a Variable with Another Variable

Hello there!

I’m trying to figure out how to set a variable from another variable. In this case, the name of the main character’s Significant other (SOname) starts out as something they can choose. Later on, they have the possibility of dating a New Person whose name they also chose (NPname). I’d like to be able to set NPname as SOname, if possible, but, obviously, the technique I tried below didn’t work at all. Any thoughts?

*temp SOname ""
*set SOname "Max"
*temp NPname ""
*set NPname "Alex"

My significant other is ${SOname}, and ${NPname} is a new person.

*set SOname=${NPname}

But now I am dating ${SOname}.

Thank you, in advance!

are you asking how to have 2 different names, cause there is a easier way. i am not a pro coder so your coding seems very different to me, it may just be that i am too dumb or your doing it wrong. if you want to get a variable from another variable you have to:


name: "Bob"
SOname: "Rachel"
*if (name= "James")
 *set (SOname= "Angela")

you have to do this in mygame.js because codes don’t work in the stats.txt
well atleast not in the version i have
and you have to have preset names which they can change later but you must have something in the “”

@CJW
i am not sure if i did this right you prob know better.

I apologize. It’s complicated to explain! Let me try again. At the beginning of my story, the main character has a significant other, and they can choose this person’s name, which becomes the variable “SOname”. Sometime later in the story, they meet another person, and they can choose this person’s name too, which becomes the variable “NPname”. At some point, the main character can choose to break up with SOname and date NPname instead. So, in this instance, I would like to convert the NPname variable to the SOname variable so that from now on the person’s significant other will have the new name.

And it’s quite possible that my code is strange. I’m not an expert either. Plus, in this instance, it doesn’t work!

Mind you, the temp variables are there as place holders to test variables that normally will be in startup.txt.

Thank you for your replies! I hope this is clearer.

1 Like

Just tested this and it seems to work, not sure if there’s a less awkward way to do this:

*create so_name "Alice"
*create np_name "Bob"

You broke up with ${so_name}, and then you met ${np_name}.

*temp name_source "np_name"
*set so_name {name_source}

Now you're dating ${so_name}.

See the very last section in http://www.choiceofgames.com/make-your-own-games/choicescript-advanced/

Sigh. Stupid mistake. Thank you, Aetheria. You helped me see what I was doing wrong. :slight_smile:

This is how it should be:

*temp SOname "Max"
*temp NPname "Alex"

My significant other is ${SOname}, and ${NPname} is a new person.

*set SOname "${NPname}"

But now I am dating ${SOname}.

Glad you figured it out. :slight_smile:

*set npname soname

Will work just as well, no need for brackets or quotations.
It’s also worth noting that CS isn’t case sensitive, so soname is the same as SOname etc.
We tend to advise sticking to lower case names, but it shouldn’t usually matter if you’re doing it for legibility purposes.

That certainly seems to be the most straightforward method. Thank you, CJW!