Random generation with split adds a blank result

Hi there!

I'm using Quest to create a random generate with the split () function, like so:

game.race_list_1 = split ("Human;Elf;High Elf;Moon Elf;Dark Elf;Gnome;Dwarf;Halfling;Orc;Troll;Ogre;Molt;Fairy;Fetchling;Satyr;Ancient;Avari;AI;Merperson;Patagi;Titan;Dionae;")

race_selection = StringListItem (game.race_list_1, GetRandomInt (0, ListCount (game.race_list_1) - 1))

These two lines effectively create the string list for me with split, and the race_selection line picks from that list created in the previous line and assigns it to that variable. Simple enough, but since I'm a beginner at coding and I nicked this code from one of the other posts on the forum, I can't for the life of me figure out why it's returning a blank result as it it's just another entry in the list when I actually generate it. This goes for every single list created by this means, often making a result like this:

The woman before you is a . She has nil skin. This is an error. Her face is exotic, with protruding This is an error. eyes, a hawk nose, and lips.

She is motivated by prestige. Her favorite sin is Lust. Her personality type is the Commander.

It outputs readable errors because I allowed the else on the skin_color, eye_shape, and the hair message, but that's the gist of it. Can anyone help?

Try this:

game.race_list_1 = split ("Human;Elf;High Elf;Moon Elf;Dark Elf;Gnome;Dwarf;Halfling;Orc;Troll;Ogre;Molt;Fairy;Fetchling;Satyr;Ancient;Avari;AI;Merperson;Patagi;Titan;Dionae")

The string (the bit between the quotes) is split on every semi-colon. As you had one at the end, it also split there, giving an empty string as the last entry.

As Pixie says, the ; at the end of the list creates an extra item containing the characters after it.

Might be worth noting that there's a quicker way to write your second line:

race_selection = PickOneString (game.race_list_1)

The PickOneString function (which is part of the core libraries) selects an item at random from a stringlist. (it's exactly the same as using GetRandomInt, ListItem, and ListCount like you did. Just quicker to write.

Thank you all so much! Working wonderfully now. <3

Shouldn't a split be:
x=split ("1,2,3", ",")
With the last "," telling split where the splits is???
Or is ";" the default, and you need to tell it you are using something different?

with pixie's newer versions of quest, it understands that the default SEPARATOR is the semicolon:

VARIABLE = Split ("red;blue;yellow") <-----> VARIABLE = Split ("red;blue;yellow", ";")

so, it saves you a little time/typing (and I thought I was lazy, lol)

if you want the SEPARATOR to be different, than you got to tell it so, as computers can't read minds either (at least without connections to the mind, lol):

VARIABLE = Split ("redMblueMyellow", "M")

I still put in the separator even though I'm using the default semicolon... as I'm still using an older version before this was put in, so still in the habit of doing so...

Personally... I think I will stick to "old school"...

This topic is now closed. Topics are closed after 60 days of inactivity.