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?
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).
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).
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.
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.
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:
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.
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.
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
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
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
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?
…