Still thoroughly confused about ChoiceScript

So I got myself a good idea, and even some programming background (VB6 and some very basic C#), yet, I still am having a hard time make sense of ChoiceScript. I would much rather prefer being able to just make the games all in C#, though of course that wouldn’t be allowed.

Anyway, I’m confused. How exactly does ChoiceScript work? I’ve been reading through the DevWiki for a few days now, but I just can’t piece it all together…

So heres a few questions:

Do I have to set stats I want to use every scene?

Where are stats held? In what .txt I mean?

When I want to transfer the user to a particular scene after a choice, do I use the “*goto_scene Nameofscenehere” command? What do I put after goto_scene? The name of the .txt file that the scene is in the scene folder

How do I change stats with a choice? Say I wanted to add 5 Strength to the player after a choice; would I type “*set Strength + 5” to do this?

Why is it that whenever I open up web/mygame/index.html to test my game, I get several errors in Opera, Chrome, Internet Explorer, and Mozilla? How can I make these errors go away? Preferably in Opera.

Where do I type out the starting stats? I assume the choicescript_stats text, but moreso, *how* do I type out the stats to make them?

And lastly, the Wiki never covers how to set what scene is the starting scene… How do I do this?

  1. You set the stats (variables) you want to use in mygame.js, or if you want, you can set them in every scene using the *temp command (although these don’t keep their value from scene to scene).

  2. The stats are held in the choicescript_stats.txt file (that’s where the player gets taken to when he presses the “Show Stats” button).

  3. You just write “*goto_scene next” for example, and it will take the player to the scene named “next.txt” in the folder /mygame/scenes.

  4. You would indeed type “*set strength + 5” in the body of that choice:


*choice
----#Strength.
--------*set strength + 5
--------*goto Next
----#Intelligence.
--------*set intelligence + 5
--------*goto Next
*label Next

Also, don’t use capital letters for variable names (instead of “Strength”, write “strength”, both in mygame.js and in your scenes.

5.First, you find the cause of the error (the message the error gives you) and the line of the error (included in the message of the error). Then, look on the line that the error message specifies and search for what could cause the error. Also, I’d recommend using Firefox for testing purposes as it has advanced error messages.

6.You use the *stat_chart command to display them:

7.You simply write the starting scene the first scene in the “sceneNavigator” in mygame.js.

I hope it’ll help!

1 Like

Do I have to set stats I want to use every scene?

Only the tempory ones for use within that scene alone. Permanent variables are defined in advance and can be referenced by name in any scene.

Where are stats held? In what .txt I mean?

Permanent variables are defined in mygame.js. Temporary ones are created as needed (with the *temp command) in each scene.

When I want to transfer the user to a particular scene after a choice, do I use the “*goto_scene Nameofscenehere” command? What do I put after goto_scene? The name of the .txt file that the scene is in the scene folder

Yes, precisely that.

How do I change stats with a choice? Say I wanted to add 5 Strength to the player after a choice; would I type “*set Strength + 5” to do this?

Yes, but you should never use capital letters in a variable name like ‘strength’.

Why is it that whenever I open up web/mygame/index.html to test my game, I get several errors in Opera, Chrome, Internet Explorer, and Mozilla? How can I make these errors go away? Preferably in Opera.

By tackling them one at a time! Opera is not very good for this purpose. Ideally, use Mozilla Firefox and a text editor capable of displaying line numbers. The wiki does have a section on error messages but it still needs a lot of work to be comprehensive.

Where do I type out the starting stats? I assume the choicescript_stats text, but moreso, *how* do I type out the stats to make them?

Follow the stats examples on this page -

And lastly, the Wiki never covers how to set what scene is the starting scene… How do I do this?

Your starting scene is whichever is first in the sceneNavigator list of mygame.js The wiki covers that early in the tutorial:

Edit: 1 minute! lol

@Vendetta, I ninja’d you ^^

Heh, yep. Interesting how we read two of the questions very differently, although your interpretation of question 6 seems more accurate, when I read it again. :smiley:

Since you have a bit of programming experience, it might benefit you to know the following as well:

  • Choicescript is interpreted as (or converted to) javascript.

  • Unlike javascript, VB6 and C#, your indentation in choicescript has an effect on your code’s execution.

This is in exchange of opening/closing tags:


*if (num = 1)
 This text will only show if num is 1
This line will always show

As opposed to javascript (and likely C# and VB6 to a certain extent) where it would be:


if (num == 1) {
                         document.write("This text will show only if num is equal to 1!")
}                                                              document.write("This text will show!")

The javascript code isn’t indentation sensitive, so although that’s poorly constructed, it should execute well enough. Choicescript however uses indentation as if they were opening/closing tags - if that helps at all.

The variables are actually held in the browser, but may be defined in any included javascript file or choicescript text file.

the *temp command creates local variables, where a text scene is considered the function (so you’d lose the value when traversing scenes).

Anything made with *create or defined in mygame.js would be global and accessible indefinitely throughout a single session of your game.

In regards to your errors, tackle them like you would errors in any other language.

Thank you all for your answers! This seems to be a far easier language than I though! Though I am getting an odd error…

Here is my code:
}
Are there choices below?

*choice
#Yes!

#Perhaps.

#There may or may not be, but that is irrelevant.

*finish
{

(Sorry, I don’t know the HTML markup for code)

I get an Expected choice body line 9 error when I execute it in firefox… Solution?

(pre) and (/pre) but replace the brackets with HTML’s <> and <>
That’s important, so we can see your indentation.

Assuming that’s correct however, it’s telling you that you need to define what each choice does - it won’t let you define an “empty” choice:


*choice
    #First
     This is the first choice body
     *goto label1

    #Second
     This is the secondchoice body
     *goto label1

    #Third
     This is the third...
     *goto label1

I should note that the choice body needs to be further indented, past the choice definition.


*choice
 #FirstChoice
 This is wrong

*choice
 #FirstChoice
   This is right

Almost . . . just bear in mind that however many spaces you use for one indentation level (1 space, 2, 4, whatever) you have to use the exact same number of spaces for one level throughout the file.


*choice
  #FirstChoice
    This is right

*choice
    #FirstChoice
        So is this

(Just not both within the same scene!)

Okay thank you, I got it working. But CJW, what is a “choicebody”? Is that just where you type the functions of the choice?

Also, do I need to double space every line I do?

Yes, it’s the code that is executed if that choice is seleced.
As Vendetta said, it doesn’t matter how big your spaces are, but yes, they do need to match.


*choice
    #Choice One
       part of the choicebody
       *set var ("one")
       *goto next

    #Choice Two
       part of the choicebody
       *set var ("two")
       *goto next

As you can see the choice body shares an indentation level, as does the choice definition.

However:


*choice
           #Choice One
                   part of the choicebody
                   *set var ("one")
                   *goto next

           #Choice Two
                   part of the choicebody
                   *set var ("two")
                   *goto next

This code should be just as valid^

This code, is not, however:


*choice
           #Choice One
               part of the choicebody
                   *set var ("one")
                *goto next

                     #Choice Two
                 part of the choicebody
               *set var ("two")
                   *goto next

Okay thank you, I did a few tests running through a few scenes and its all working very well.

Though I have a question regarding stats; sorry for asking so much, I seem to have a disability to learn from the wiki… I read it but it doesnt seem to process very well with me… How peculiar…

Anyway, what is the difference between the stats in the “mygame.js” file and the “choicescript_stats” text? Whenever I try to set a variable in the text file, I get an error when trying to read the stats; and when I leav the text file blank, nothing appears when I click stats…

choicesript_stats is a special page for displaying the values of stats/variables to your players, it’s not used to define stats/variables, thus you must have defined a stat/variable elsewhere to be able to use it within choicescript_stats.

And it’s no problem, really, we all have to start somewhere!
If you feel the wiki is too hard to follow though, I’d love it if you could take some time to comment on it’s discussion to let us know how we might best improve it :slight_smile:

So I set my variables in the .js file? How does the text file display the variables in the .js file? I’m confused…

To print a variable inside a text/scene file you type its name with {}'s preceded by a $:


${varname}

in the mygame.js file you’d have something like this:


stats = {
         varname: "SSoeiro"
}

Meaning that if you type ${varname} in a text file, when viewed through a browser/in-game - it’d show up as “SSoeiro”.

when you have two choices to make, how do you make sure their separate, for example say u have a choice of taking a shower or eating breakfast, you choose breakfast, how is it possible to separate the 2 choices

sorry for any confusion, this sounded a lot better and a lot simpler in my head

By using indents, *goto, or *finish.

In the example “—” simulates a tab stop.

How do you want to begin your day?
*fake_choice
#Have breakfast
------You sit down and have a wholesome breakfast of cornflakes.
#Take a shower
------You take a shower, and emerge damp but fresh-smelling.

Your day continues…

In that case the fake choice just gives a bit of varying text based on the player’s selection, then continues along. If you have scenes in order in your startup.txt, you can *finish to drop to the next scene:

*scenes
—morning
—afternoon

(then in morning.txt)

How do you wish to start your day?
*choice
#Eat breakfast
------You have a hearty breakfast of oatmeal.
------*finish
#Take a shower
------You take a shower and emerge damp but fresh-smelling.
------*finish

In this case, the player makes a choice, gets an alternate next, and then the scene ends and the game proceeds with the next in the list. In this case, afternoon.txt.

However, you could diverge more seriously using *goto or *goto_scene. Say the story has two different scenes depending on what the player does, “afternoon_hadbreakfast.txt” and “afternoon_tookshower.txt”

How do you want to begin your day?
*choice
#Have Breakfast
------*goto_scene afternoon_hadbreakfast
#Take a shower
------*goto_scene afternoon_tookshower

You could also plain *goto a *label within the same file.

How do you want to begin your day?
*choice
#Take a shower
------*goto shower
#Have breakfast
------*goto breakfast

*label shower
Nnnghh! Hot water!
*fake_choice
#Lather
#Rinse
#Repeat
#Done
------Well, that was refreshing!
------*goto afternoon

Ah, showering feels great!
*goto shower

*label breakfast
You sit down for a hearty breakfast.
*fake_choice
#Eat Eggs
#Eat Toast
#Drink Orange Juice
#Finished
------What a hearty breakfast you’ve had!
------*goto afternoon

Yum!
*goto breakfast

*label Afternoon
Okay, now how would you like to spend your afternoon?

1 Like

Guys this question is 3 years old… wtf

1 Like

thanks but it still won’t do it, im really close to giving up cause I have been trying to do this for at least two days now and nothing has worked

What is is not doing? Have you followed the setup directions and read how CS works?

Try using the online IDE to see if you can get a hang of the language without the setup problems first

https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/IDE/main.html#