Error with mygame.js


So first off thanks for approval into the group and very excited to be here. I have searched through the discussions here and havnt quite found my error. well there was one person but they answered themself lol. My error is when defining a name as a variable in mygame.js the problem is I have no idea how to lol…
here is mygame.js

nav = new SceneNavigator([


// Specify the default starting stats here

stats = {
leadership: 50
,strength: 50

// Specify the stats to use in debug mode

debugStats = {
leadership: 50
,strength: 50

// or just use defaults
// debugStats = stats

and my variable file

Before we continue we should get some information about you. What is your name?

Insert your first name.
*input_text name


Insert your last name.
*input_text lastname


Well {name} {lastname), What is it you do to support your family?

if any one can assist me with this it would be greatly appreciated


Looks to me like you just need to define your two new variables in mygame.js, so that section looks something like this:

leadership: 50
,strength: 50
,name: “none”
,lastname: “none”

The two *input_text commands will then overwrite “none” with the text entered, so that {name} and {lastname} will display correctly when used in your story.

Note that you can just leave them blank at the start, using double quotes, e.g.

,name: “”
,lastname: “”


Note: You have to use those quotes whenever you make a text (string) variable in the mygame.js file. Otherwise, you don’t need quotes.


awsome!! thank you so much!


Well sorry to be asking questions again but is that also true for setting an occupation.
my character is a paramedic and in the invintory avail there is a first aid kit which is disabled unless paramedic.


You can add as many new variables as you like to mygame.js. All you really need to decide is the best type to use in each instance–whether boolean, numeric or string.

A boolean is a simple switch, either true or false, which you would define in mygame.js as e.g.

,first_aid_kit: false

At any point in your story you might give the player a kit with:

*set first_aid_kit true

A numeric variable holds a numeric value of zero or greater (no surprise there!), which you would define in mygame.js as e.g.

,occupation_type: 0

At any point in the story you might make the player a paramedic with:

*set occupation_type 1

which would allow for a whole range of occupations, each assigned a numeric ID, so in the story you can use conditions like:

*if occupation_type = 1


*if occupation_type != 1

The second example means “if the player is NOT a paramedic”.

Finally, a string variable is used for holding any text, which you would define in mygame.js as e.g.

,occupation_name: “none”

but later on change that accordingly in the story with such as:

*set occupation_name “Paramedic”

In conclusion, have a good think about your game design (pencil and paper work for me!) and decide what kind of things you want to include and how each game element might be used in the story, and then decide what type of variable would be best to use for each one.


thanks again! I have never done any scripting before so this is all me learning as i am going with my story lol :slight_smile:


@Vendetta, the integrer (numerical variable) can hold negative amounts in my knowledge (at least, all integrers can in the other programming languages, so why not here?). But anyways, that’s not very important since most people don’t really use negative values in a game in ChoiceScript (it depends by the game, but most people don’t).

Also, about the “*if occupation_type != 1”, to make that easier to understand, you can make it like this:
*if not (occupation_type = 1)
Note: Paranthesis required!
But that’s up to how everyone uses it. I use “not”.


@AlexCosarca Useful additions for someone to bear in mind. I’ll personally stick with != for “not equal to” though, simply because I tend to use a lot of less than, greater than, equal to or greater, etc., so it keeps the same format for them all rather than have that one exception to the rule.

More to the point, I also find that I often use multiple conditions on the same line, with “and” & “or” as applicable, and the logic for those lines can be complicated enough (especially for a non-programmer like me) without sticking a “not” at the beginning! :smiley:


@AlexCosarca, as I found last year, there are some problems with variables that go negative. Stats can go negative, but you can’t then do much with them; coding like

*if stat = -5


*if stat < (-2)

will just get you an error message.


@Havenstone, I never tried that, and I never needed to use negative stats, but now that you told me about these errors, here’s a point for everyone to keep in mind (about negative stats):
Whenever a stat decreases, try using

*if stat < 0
    *set stat 0

Now that I know about this error, this is highly recommended (I always used this, though I never thought about errors with negative values).


Well, that’s one way to deal with it. I use two different ways to dodge the error myself:

  1. Re-center stats. If the stat decreases in your game are likely to take you negative, you can always declare 200 (or some other appropriately high number) to be the new zero. I did this with a stat called “cred_a” (credibility with the aristocracy). At 200, the aristocracy don’t think much of you either way. Less than 200, they begin to despise you; higher than 200, and they begin to admire you.

  2. Allow negative stats, as long as it’s not important to distinguish them once they fall below zero. For example, I’ve got a stat called “k_rel” that measures your relationship with a character named Kalt. There are lots of things you can do to antagonize Kalt, and each of them decreases k_rel by varying amounts. But once you fall below zero, it doesn’t matter whether you’re at -1 or -25, Kalt’s just plain going to hate you. So I can use *if k_rel < 0 (which works just fine) for all negative stat purposes.

These ways have the slight advantage that you don’t have to insert two extra lines of code every time you decrease a stat.


There shouldn’t be any issue with negative stats… They’re still integers?
That’s strange.


As far as I can make out, the problem isn’t with the integers, but the sign “-”, which in ChoiceScript means minus, not negative; it doesn’t have the dual meaning it does in normal language.

So CS can understand “*set stat -5”, but not “*if stat = -5”.

If there’s another symbol that can be used to denote negative integers, I’ve not found it. And I’ve not found it that hard to work around anyway…


Whenever I try to load my game, an error message appears saying "expected identifier, string or number.
this is my mygame.js file:
// Specify the list of scenes here, separated by commas, with no final comma

nav = new SceneNavigator([


// Specify the default starting stats here

stats = {
name: “”
,faction: “”
,gender: “”
,race: “”
,class: “”
,Racial_ability: “”
,Base_ability: “”
,oppfac: “”
,abilities: “”
,XP: 0


// Specify the stats to use in debug mode

debugStats = stats

// or just use defaults
// debugStats = stats


You can’t use ‘class’ as a variable name, since it’s a key word in javascript.
Call it cclass or something?


Done that but now I get “Syntax error” although I can see no problems with the syntax.


How about losing the capital in Racial and Base?


Did that but still same error message.


Solved it. Forgot to set name as string. Thanks for the help:)