Injecting Character

I don’t know what is it called in programming theory but, what I want is adding and swapping characters on text with anything I desire.

Example: I made a character named “John”

and I want his name to change into “Joanna” with these steps:

  1. swap third character ‘h’ with ‘a’, now it’s “Joan”
  2. add ‘na’ at the end of his name, now it’s “Joanna”

how do I write codes in choicescript to perform this task?
please help, thank you

1 Like

You can indeed inject specific characters to alter what’s written per player set up, but it tends to be easier to just replace the whole word/phrase depending on the needs of the situation.

Basically, you’ll want a list for both John, and Joanna on the startup file featuring their names, pronouns, and other details that are character specific, like hair length for example.

The term you’re looking for is “String Manipulation”. If you tell us what exactly you are trying to accomplish, we might be able to help you find a solution.

Keep in mind that ChoiceScript is not the best language to perform heavy or intelligent string manipulation. You can change a character if you already know the character’s position.

To change a name like in your example cannot be done efficiently, even in other programming languages. It would be best to hard code a set of names to be able to shift back and forth.

*if ($!!{name} = "JOHN")
	*set name "Joanna"
2 Likes

guess I just have to request closing to the @moderators and accept the lack of string manipulation in choicescript, thank you.

As cup says, ChoiceScript tends to fall a bit short here.
But I want to point you towards CSLIB (notably the string module), which goes some way to plugging the gap. The end result still isn’t very performant though.

Example:

*title cslib-name
*author CJW

*comment Configure CSLIB
*create implicit_control_flow true
*create cslib_ret ""

*create name "John"
${name} = John,
*gosub_scene cslib_string replace name "h" "a"
*set name cslib_ret
${name} = Joan,
*set name &"na"
${name} = Joanna
*finish
1 Like

You’ll find it’s way easier to do this without any string manipulation at all, as others have pointed out.

Startup

*create john_gender 0
*comment 1: nb, Joan
*comment 2: m, John
*comment 3: f, Joanna
*create john ""

In Your Game

*if (john_gender = 1)
  *set john "Joan"
*if (john_gender = 2)
  *set john "John"
*if (john_gender = 3)
  *set john "Joanna"

$!{john} spits out @{john_gender+1 |their vodka sour|his mojito|her old fashioned whiskey}. "Why do they always assume I want to order this? This isn't what I wanted! Eat my ass, Steve!"

"Eat your own ass, $!{john}, you've got a tab a meter long, stop coming here!"
2 Likes

Just checked the library, and that’s some impressive works I must say.

Will it prevents me from releasing a game? or it’s an official library?

It’s not “official”, but it shouldn’t cause publication issues as it’s written in 100% pure ChoiceScript.

2 Likes