How to add onto existing variable?

search function letting me down, so here goes.

How can I add onto an existing variable. I’m trying to write an example on how to carry information form two different games into one, and was going for the password that could set variables. but I’m uncertain as to how set said password variable in the first place. What I want to do is this.

have a string variable ‘password’
at the end of a game the game would run a lengthy subroutine to turn all important stuff into numbers in that variable. And I want each bit to add onto the existing variable.

Like

*if (gender =1)
   *set password "1"
   *goto race
*elseif (gender =2)
   *set password "2"
etc

*label race
*if race ="human"
   *set password "${password}" + 1
*if race ="dwarf"
   *set password "${password}" + 2

for example.
How to have it that after the ‘race’ or whichever label the full string would e.g. be “32”?

I don’t know if this is the most elegant way to do it, but I think you could do it with multiple variables

For example (modifying your code):

*if (gender =1)
   *set step1 "1"
   *goto race
*elseif (gender =2)
   *set step1 "2"
etc

*label race
*if race ="human"
   *set step2 "1"
*if race ="dwarf"
   *set step2 "2"

*set password "$!{step1}$!{step2}"

I’ve tested to see if this works, and it appears to. Screenshots attached.

Pics

create
set
display

ETA: Although not immediately relevant to the question you’ve posed here, I think this topic belongs in the general conversation since it theoretically works in the opposite direction → extracting a character from an already created string (which could be a password)

I was hoping for a way to simply add ONTO a variable, cause for what I have in mind the generated passwords could get long.
but thanks

1 Like

I think you could still do that. Let me modify the code again:

*if (gender =1)
   *set password "1"
   *goto race
*elseif (gender =2)
   *set password "2"
etc

*label race
*if race ="human"
   *set password "${password}1"
*if race ="dwarf"
   *set password "${password}2"

Haven’t actually run this code to check but there’s no reason why it shouldn’t work?

1 Like

Thanks. I’ll try it later and check if it can go back and forth :3
cause, i think there are authors out there who might have great fun with it if it works

2 Likes

It worked :smiley: making a thread now to share the code

4 Likes

If you’re concatenating string variables, I would use an ampersand as explained here. It’s worked well for me.

5 Likes