How to select Characters From a String


#1

I know most programming languages have a function where you can pull individual characters out of a string. for example if I had a first name and wanted to know the first initial, what could I do?

*create name “John”

*create initial " "

*comment I would like to have something like

*set initial “${John}[1]”

*comment and have it print

${initial} = J

is there anything like that in ChoiceScript? It would play a pretty significant role in my concept for a game… I would really appreciate it!


#2

Unfortunately, no, there is no breaking up strings in ChoiceScript.


#3

Well that’s disappointing but I really appreciate your prompt reply! Time to start getting creative I guess…


#4

What did you want to do with this technique?


#5

well I wanted to create a story where the reader could choose one of several characters to accomplish an objective and track that characters stats separately. I was hoping to do so by creating variables such as armor_1 armor_2 and so on. If the reader decided he wanted to send character 1 on the mission then I wanted to be able to affect the variables accordingly.

for example, if the user sent char_1, who has his own strengths and weaknesses, to defend a bridge I could create a quick command to retrieve the 6th character in the string and make it a temp variable. then I could drop it into other variable using commands such as

armor_[temp variable] or health_[temp variable] which would then affect armor_1 or armor_2 or 3 respectively.

this would allow a deeper level of tactics where the reader has to get to know his characters and make decisions on when to use one vs the others without crutching on one too much.

hopefully I’m not showing my ignorance too much…


#6

Oh, that’s much easier than what you requested. You asked to remove the first letter of the word “John” to get a “J,” but you just want to glue two known variables together.

For that, you can use the *setref command and curly parentheses, defined in the Advanced Choicescript guide.

*setref "armor_${number}" %+70
*set current_armor {"armor_${number}"}
Your armor_${number} = ${current_armor}

#7

That is very easy! Thank you so much for taking the time to help me out! I’m brand new at this so my mind couldn’t fathom more than one way to do that.

I figured it would be easier to explain through the john example…knowing what I know now however… : )