Help my Code.... The Civil Evolution


I’m currently in the process of coding my first chapter for my Game Civil Evolution since I’m likely to encounter many, many errors which I may not know how to get around I’ll just post them all here.

I’m currently trying to create a series of Generators that “create” random values like the Person name, gender and what race they are uplifting.

I’m using the *gosub command to go to each generator in turn

*create Companion1 "FirstName"
*create Companion1Last "LastName"
*create Companion1Distance 1
*create Companion1RaceName "Human"
*create Companion1Gender "man"
*create Companion1Race "Human"
*create Companion1Arc "Biologist"
*create Companion1Cyber "legs"
*create Companion1Gener false

*create companionx "Companion1"

*label Generator
*if Companion1gener = false
	*set companionx "Companion1"
	*gosub GenderGenerator
	*gosub NameGeneratorFirst
	*gosub NameGeneratorLast
	*gosub CompRaceGenerator
	*gosub DistanceGenerator
	*gosub RaceNameGenerator
	*gosub ArchetypeGenerator
	*set Companion1gener true
	*goto Generator

It then loops untill all Companions are created and then *goto Start
I get an Error in this code

*label GenderGenerator
*temp Gender
*rand Gender 1 2
*if Gender = 1
	*set ${companionx}Gender "man"
*elseif Gender = 2
	*set ${companionx}Gender "woman"

Could not extract token on *set {companionx}Gender "man" and *set {companionx}Gender “woman”

I’m not sure why, but its probably something realy simple that I’m missing.


The only thing I see that could be problematic is the part that you create the variable “Companion1Gener false” but later use Companion1gener. The G in Gener is small. I don’t know how the CS checks variables but that could be a problem.

Edit: Also I think you should only use lower case letters for CS variables but I am not sure.


Thanks for the reply I am pretty sure the Case (g,G) is not an issue but I tested it anyway.

no effect I still get
a could not extract another token {companionx}gender "man" or a could not extract another token {companionx}gender “woman”


One thing I could think of would be that your temp Gender has to be declared as numeric.

temp Gender 0

Also to further investigate the problem why not try to print your variables so you can see whats in them.

*label GenderGenerator
*temp Gender
*rand Gender 1 2
*goto CheckVar

Then somewhere else

*label CheckVar
*print Gender
*print companionx


Okay, so, because I’m not clear on what you’re trying: First: don’t use *if or subroutines to *create variables. *create commands should all go in the top of the startup file. *create, *scene_list, *title, *author, and *achievement are all Initial Commands. One any other command is used, those commands are permanently closed with only *comment being a special case. (This is bug prevention.)

Second, I think you should look at this:

*label GenderGenerator
*temp Gender 0
*rand Gender 1 2
Gender is ${Gender}
*if Gender = 1
	*set ${companionx}gender "man"
*elseif Gender = 2
	*set ${companionx}gender "woman"

It produces a 1 or 2 then after the next page. could not extract another token {companionx}gender "man" on a 1 or {companionx}gender “woman” on at 2


Thanks for the reply!

the *Create are in the Setup.txt at the top as they should be I’ve only included them to show that I have created the variables I’m calling. there are no *create after the main block of code starts I have only used *temp after that point,

the Error points to *set {companionx}Gender "man" or *set {companionx}Gender “woman” when it generates the error

I will read throu your link there and see if I can spot a solution thou.


Ok, I think it doesn’t like you putting the ‘$’ in the *set command. You may need a hold variable in there to set the variable name.

Assuming you have something like this in your startup.txt

*create Alice_gender ""
*create Bob_gender ""

Then something like this should work:

*temp holdvar ""
*set companionx "Alice"
*set holdvar "${companionx}_gender"
*set {holdvar} "woman"
*set companionx "Bob"
*set holdvar "${companionx}_gender"
*set {holdvar} "man"

Alice is a ${Alice_gender}.
Bob is a ${Bob_gender}.

Edit: with your example:

*label GenderGenerator
*temp Gender 0
*rand Gender 1 2
Gender is ${Gender}
*temp holdvar ""
*set holdvar "${companionx}gender"
*if Gender = 1
	*set {holdvar} "man"
*elseif Gender = 2
	*set {holdvar} "woman"


Thanks That did it!

My code is now working
I created 8 holding variables which I can move companion data in and out of. which will be useful later as well when I start writing the companions interlude stories.

*elseif Companion6gener = false
	*set CompanionxName "Companion6Name"
	*set Companionxlast "Companion6Last"
	*set CompanionxRace "Companion6Race"
	*set CompanionxDistance "Companion6Distance"
	*set CompanionxRaceName "Companion6RaceName"
	*set Companionxgender "Companion6gender"
	*set CompanionxArc "Companion6Arc"
	*set CompanionxCyber "Companion6Cyber"
	*gosub GenderGenerator
	*gosub NameGeneratorFirst
	*gosub NameGeneratorLast
	*gosub CompRaceGenerator
	*gosub DistanceGenerator
	*gosub RaceNameGenerator
	*gosub ArchetypeGenerator
	*set Companion6gener true
	*goto Generator

And this is my new generator code for reference, I’ve tested it and it works without a problem.
Thanks, @ChibaHateme, @RETowers, @Scribblesome, for helping me work through my issue!


is there any way to round to a specific decimal place?

for example, sometimes my Random Distance generator comes up with a number that is really long in

*label DistanceGenerator
*temp Dis1 0
*temp Dis2 0
*rand dis1 1 5
*rand dis2 0 100
*set {companionxdistance} dis1 + (dis2 / 100)

like this one
Companion 5:
Name: Eunomia Ardelean
Gender: Woman
Race: Neo-chimpanze
Archetype: Botanist
Distance: 1.8900000000000001ly <--------------------too many decimals
Rules Race: Aptotti


There is a round function, outlined on the Arithmetic Operators page of the Choicescript wiki.

I’m not completely sure, but you could try

*set ${companionxdistance} round(dis1 + (dis2 / 100))

You might run into trouble with the {} again. I tried it out and I could get it to set `companionxdistance` but not `{companionxdistance}`.

I think it only rounds to the integer, though.

I suppose it would be possible to round to the integer after multiplying by 100 if you wanted two decimal places, and then divide the resulting quantity by 100 after the number was rounded…something like:

*set companionxdistance round((dis1 + (dis2 / 100)) * 100)
*set companionxdistance / 100

There might be an easier way to do it, but I haven’t experimented much with the round function.


Could you show maybe the part where you:

*create Companion1Distance 0
*create […]
*create Companion5Distance 0
*create Companion6Distance 0

I think you probably have declared every one of them as numeric by giving them the starting value 0. However, if you didn’t this could lead to the problem. But I would also think the code wouldn’t work as a whole if the Distance isn’t already declared as numeric.

Fiogan’s idea is quite nice I would say. However, I would rather multiply dis1 by 100 and add the value of dis2 onto it. Then I would round it and divide it by 100 at the end. With this, the first step should only produce integer numbers between 100 and 600. Fiogan’s example does the same but I am a bit scared of the operation dis2/100. I would avoid decimal numbers as long as possible.

Example Code:

*set {companionxdistance} round((dis1 * 100) + dis2)
*set {companionxdistance} / 100

If you still have the problem then it’s probably created by dividing by 100 and creating decimal digits as a whole.


confirmed that they are all sitting at 1

Your code seems to have fixed it so I’m going with that.

Yet I’m still unsure where the really long decimal was coming from. :slight_smile: probably an anomoly caused by the *rand command

Thanks @ChibaHateme and @Fiogan for your help!


I have a question. Is it possible to color some lines of text in choice script?

I’m particularly intrested if I can get some choices color coded based on an *if statement?


I haven’t used the font changing text, mostly because it would add unneeded complications to my coding, but here is a post that may help you:

I’m sure you can change the font by just using *if statements and tabbing whatever you want to write under it.


Thanks that was helpful!