Rolling a random name

I am planning to do a similar thing to this a few times in my current (and first) project. Basically there is an invisible roll happening determining a variable that will influence some choices and outcomes for the player. This first one sets the player’s ‘‘homeland’’. The result will not be directly told to the player but revealed indirectly (with changes in the text).

But I can’t figure out the code to 1 do a diceroll for determining which of 6 nations is the homeland.

I have tried to phrase this in my script in several different ways but I keep getting error messages.

The error I’m currently getting is: ''invalid expression, couldn’t extract another token ‘‘USA’’. If I switch USA in the Create Homeland line with a number, the same error shows up later in the code when the Nation roll should be converted to the actual name.

My code now looks like this:

*create nation 1
*create homeland ‘‘USA’’
*rand nation 0 5
*if nation = 0 Set ${homeland} USA
*elseif nation = 1 Set ${homeland} Russia
*elseif nation = 2 Set ${homeland} UK
*elseif nation = 3 set ${homeland} France
*elseif nation = 4 set ${homeland} China
*elseif nation = 5 set ${homeland} India

I can’t figure out where my logic is faulty in interpreting the text, and the various tutorials I have found all seem to point to either purely using numbers, having the player choose from options or the player putting in text. I have tried several variations with quotation marks, brackets and a few other factors.
I’m sure the way to do this is fairly obvious, but after a few days of slamming my head against the door I really need some aimed pointers. How do I get the game to randomly choose one of several options?

1 Like

*create homeland means the variable is: “homeland”

The error is here and below: *if nation = 0 Set ${homeland} USA


*if nation = 0 
     *set homeland USA
*elseif nation = 1
    *set homeland Russia
...
*else

The *else statement should take the place of:
*elseif nation = 5 *set ${homeland} India

etc…

1 Like

Now I get ‘‘couldn’t extract another token’’ when ${homeland} gets checked and selected. It seems when I use ${homeland}, the problem is that (presumably) either $ or {} are not english alphabet letters, but removing them means the variable must be numeric.

The symbols: “$” and {} are used to display variables in your text. The variable is homeland not ${homeland}.

homeland is your text variable and the symbols you are citing are to display text variables when used in your writing.

Let us say the homeland variable was assigned “russia” as its value. In text, to make sure the variable shows as capitalized, you would use:

$!{homeland} is the largest nation in the world when talking about territory.

This would be displayed as: Russia is the largest nation in the world when talking about territory.

If you wrote:

${homeland} is the largest nation in the world when talking about territory

Then, it would be displayed as: russia is the largest nation in the world when talking about territory.

Here is the wiki page on displaying variables:

It took significantly more trial and error then is reasonable. But it turns out my problem was in fact in how I type quotation marks. I am used to just pressing the button twice, leading to:‘’ but it needs to be shift+the button to make ". Yeah, I don’t see the difference either but the code sure does. For those curious this is what the code now looks like (for just three nations).

*rand nation 0 2
*if (nation = 0)
*set homeland “china”
*if (nation = 1)
*set homeland “usa”
*if (nation= 2)
*set homeland “russia”

2 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.