-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChoiceScript to SugarCube Guide.twee
2626 lines (2378 loc) · 327 KB
/
ChoiceScript to SugarCube Guide.twee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
:: StoryTitle
ChoiceScript to SugarCube Guide
:: StoryData
{
"ifid": "C15CE33F-61F6-4909-BB59-73EE7A3D57B1",
"format": "SugarCube",
"format-version": "2.37.3",
"start": "Start",
"tag-colors": {
"Twine.image": "purple",
"commands": "orange",
"diff": "green",
"new": "blue"
},
"zoom": 0.6
}
:: About [diff] {"position":"700,300","size":"100,100"}
<h1>About Twine and SugarCube</h1>
//''Twine''// is a free and open-source tool to create interactive, non-linear stories, created by Chris Klimas in 2009. It is now maintained by multiple individuals, in [[several repositories|https://github.com/tweecode]]. ''//Twine//'' is also a registered trademark of the [[Interactive Fiction Technology Foundation|https://iftechfoundation.org/]].
''//Twine//'' offers both a desktop and browser application on [[its website|https://twinery.org]], giving creators a visual representation of each passage in their game. The browser version can also be opened on tablets and mobile devices.
Over the years, Twine has had [[multiple story formats|http://mcdemarco.net/tools/hyperfic/twine/catalog/]], SugarCube being among them. Twine compiles the code of the chosen format to create a file in HTML or Twee. The other base formats of Twine 2 are: Harlowe, Chapbook, and Snowman.
> ''Note:'' Harlowe is the default format in Twine. You can change the format of a project in the {{{Story > Details}}} menu.
''//SugarCube//'' is a free (gratis and libre) coding format for Twine/Twee created and maintained by Thomas M. Edwards. It is based on JavaScript and jQuery, and can be styled with HTML and CSS.
Thomas M. Edwards is also the creator of //''Tweego''//, a free (gratis and libre) command line compiler for Twine/Twee story formats written in Go. It is an alternative to Twine, and can be used with any Integrated development environment (IDE), like VSCode. <small>This guide was compiled with Tweego.</small>
If you want to support the parties named above, you can find here the links for:
* Chris Klimas (klembot) : [[Patreon|https://www.patreon.com/klembot]]
* Thomas M. Edwards (TME - TheMadExile) : [[Patreon|https://www.patreon.com/thomasmedwards]] - [[Ko-Fi|https://ko-fi.com/thomasmedwards]]
* The Interactive Fiction Technology Foundation : [[Donations|https://iftechfoundation.org/give/]]
> ''Note:'' to support other parties creating assets and resources for Twine, check this [[list|https://manonamora-if.tumblr.com/post/700577877042888704/]] (non-exhaustive).
:: Achievements [new] {"position":"1300,400","size":"100,100"}
<h1>Notes on Achievements</h1>
Unlike ChoiceScript, Twine does not come with a Built-In system for Achievements. There are no special functions to create or update the achievements. You will need to set it up manually, which can be relatively easy or more complex depending on the way chosen. This section will go over the different SugarCube substitutes for {{{*achievement}}} and {{{*achieve}}}.
Creating achievements can be done in two major ways: through a variable or by relying on metadata (cache). There isn't much difference between the two methods, aside from how they are save: the Variable way will work closer to ChoiceScript's Achievements (applied to one playthrough), while the Metadata will apply to all playthroughs on a device (until the cache is deleted).
> ''Note:'' for saves reason, the first method is recommended.
You will need to know which passages will trigger each of the achievements, as well as creating a separate passage to display those achievements (let's call it: {{{Achievements}}}). The actual display of the achievements will be done with [[conditional statements|IfElse]] for regular variables, and JavaScript functions for the MetaData.
\
<h2>Simple Variable Achievements</h2>\
This is the most basic way of creating achievements, as it relies on simple variables to track whether an achievement has been earned or not. You can use either [[types of variables|Variables]] for this: a regular variable for each achievement, or an object/array to group achievements inside one variable.
\
<h3>Creating Achievements</h3>\
These variables should be [[defined|Variables]] in {{{StoryInit}}}.
{{{
:: StoryInit
<<set $achievement1 to false>>
<<set $achievements to {}>>
<<set $achievements to []>>
}}}
> <small>In order: a simple variable, an object, and an array.</small>
In the relevant passage where the achievement is earned, you will modify the variable to indicate this change:
{{{
:: SavedThePrincess
<<set $achievement1 to true>>
<<set $achievements.savedP to true>>
<<set $achievements.push("Saved Princess")>>
}}}
> <small>In order: a simple variable, an object, and an array.</small>
\
<h3>Displaying Achievements</h3>\
In the {{{Achievements}}} passage, you will code conditional statements to check whether an achievement has been earned, before displaying it on the page. Depending on the type of variable used, there will be slight differences:
{{{
:: Achievements
<<if $achievement1 is true>>Achievement One Earned<</if>>
<<if $achievements.savedP is true>>You Saved The Princess!<</if>>
<<if $achievements.includes("Saved Princess")>>The Princess wasn't in another castle!<</if>>
}}}
> <small>In order: a simple variable, an object, and an array.</small>
If you want to make it a bit more fancy, and display some text before the achievement is earned:
{{{
:: Achievements
~ Saved The Princess:
<<if $achievement1 is true>>
You saved the Princess!
<<else>>
Rescue a VIP.
<</if>>
}}}
> <small>The return to line is not required, this is just to make the example clearer.</small>
Repeat the conditional statements until all achievements are listed.
\
<h2>Memorize and MetaData</h2>\
This method is a bit more complex, because you rely on JavaScript functions, and the player's cache. Essentially, you will tell the browser to "memorize" the achievement in its cache.
\
<h3>Creating Achievements</h3>\
There is no need to set up anything in advance, you can simply plop the code into the relevant passage (where the achievement is earned):
{{{
:: SavedThePrincess
<<run memorize("achievementName", true)>>
<<run memorize("achievSavedP", true)>>
}}}
\
<h3>Displaying Achievements</h3>\
In the {{{Achievements}}} passage, you will code conditional statements to check whether the player's saved metadata with {{{recall()}}}, to see if the achievement is there:
{{{
:: Achievements
<<if recall("achievementName") is true>>Achievement One Earned<</if>>
<<if recall("achievSavedP") is true>>You saved the Princess!<</if>>
}}}
Repeat the conditional statements until all achievements are listed.
\
<h2>The ChoiceScript version</h2>\
If you want your code to be as similar to ChoiceScript's {{{.achievement}}}/{{{.achieve}}} code as possible (setting up the achievements and displaying them) you can do something like the following. This is essentially a more complex-looking version of the Simple Variable object form (see above), but with extra setup (a [[widget|GoTo]]).
\
<h3>Creating Achievements</h3>\
For this way to work, you will need to set up each of your achievements as objects, which will include all the information about that achievement. You will have to define those objects in he {{{StoryInit}}} [[passage|SpeP]].
{{{
:: StoryInit
<<set $codename to {
gotten: true/false,
visible: true/false,
pointValue: number,
title: "Title",
preEarned: "Description Pre-Earned",
postEarned: "Description Achieved"
}>>
→ Example:
<<set $savedP to {
gotten: false,
visible: true,
pointValue: 50,
title: "Saved The Princess",
preEarned: "Rescue a VIP",
postEarned: "You saved the Princess!"
}>>
}}}
> ''Note:'' if {{{visible}}} is //false//, you won't need the line {{{preEarned}}}.
\
<h3>Setting up the Widgets</h3>\
To make the rest of the implementation easier, you will need to add the following widgets to your project, in a passage [[tagged|Tags]] {{{widget}}} and {{{nobr}}}. The first widget will do the same thing as {{{.achieve}}}, while the second will make displaying the achievements easier on the page (it will take into account whether it should be visible or not).
{{{
:: Widget [widget nobr]
<<widget "achieve">>
<<set _args[0].gotten to true>>
<</widget>>
<<widget "achievement">>
<<if _args[0].gotten || _args[0].visible>>
''<<print _args[0].title>>:''
<</if>>
<<if _args[0].gotten>>
<<print _args[0].postEarned>> (<<print _args[0].pointValue>>)
<<elseif _args[0].visible>>
<<print _args[0].preEarned>> (<<print _args[0].pointValue>>)
<</if>>
<</widget>>
}}}
> <small>If you are only copying/pasting the code for Twine, don't select the first line.</small>
\
<h3>Updating the Achievement</h3>\
When your widgets are ready, you can use them in your relevant passage, where the achievement is earned:
{{{
:: SavedThePrincess
<<achieve $codename>>
<<achieve $savedP>>
}}}
\
<h3>Displaying Achievements</h3>\
And finally, you can set up your achievements' page by using the second widget:
{{{
:: Achievements
<<achievement $codename>>
<<achievement $savedP>>
}}}
Repeat until all achievements are listed.
\
<h2>Notifying the Player</h2>\
SugarCube does not come with its own notification element, like ChoiceScript does when a new Achievement is earned. But there are ways to notify the player when they got an achievement: either as plain text on the page, a popup to dismiss, or through a custom macro creating a special notification similar to ChoiceScript's.
> //Plain Text//:
{{{
:: SavedThePrincess
<<set $achievement1 to true>>
//Achievement Earned!//
<hr>
}}}
> //Popup//:
{{{
:: SavedThePrincess
<<set $achievement1 to true>>
<<script>>
Dialog.create('Achievement Earned!');
Dialog.wiki("Yay! you did it!");
Dialog.open();
<</script>>
}}}
''Note:'' Chapel has a neat [[popup set|https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/docs/dialog-api-macro-set.md]] to make popups less daunting to set up.
> //Custom Macro//:
In this case, how to set up the notification will depend on the specific custom macro you choose. Chapel's [[notify macro|https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/docs/notify-macro.md]] and Sjoerd [[Flash macro|https://github.com/SjoerdHekking/custom-macros-sugarcube2/tree/main/Notification]] are the most well known/established custom macro to create notifications.
> ''Note:'' Sjoerd's macro is more ARIA-accessible for screen readers than Chapel's.
:: Basic Macros [twine] {"position":"500,600","size":"100,100"}
<h2>Textbox</h2>\
<<textbox "_test" 2>>
<h2>Text Area</h2>\
<<textarea "_pieEssay" "">>
<h2>Radio Buttons</h2>\
What's your favorite pie?
<<radiobutton "_pie" "blueberry" autocheck>> Choice 1
<label><<radiobutton "_pie" "cherry" autocheck>> Choice 2 with a label </label>
<<radiobutton "_pie" "coconut cream" autocheck>> Choice 3
<h2>Number Box</h2>\
<<numberbox "_wager" 100>>
<h2>List Box</h2>\
<<listbox "_answer" autoselect>>
<<option "Option 1">>
<<option "Option 2">>
<<option "Option 3">>
<</listbox>>
<h2>Cycle</h2>\
<<cycle "_answers" autoselect>>
<<option "Option 1">>
<<option "Option 2">>
<<option "Option 3">>
<</cycle>>
<h2>Check Box</h2>\
<<checkbox "_pieBlueberry" false true autocheck>> Option 1
<label><<checkbox "_pieCherry" false true autocheck>> Option 2 with a label</label>
<<checkbox "_pieCoconutCream" false true autocheck>> Option 3
<h2>Button</h2>\
<<button "I do not do anything">><</button>>
:: Choices [commands] {"position":"900,500","size":"100,100"}
<h1>Having Choices and Linking Passages</h1>
Because of the difference in structure between the two systems, creating choices and linking different parts of the game is also formatted differently. ChoiceScript allows you to indent your choices, nesting them within each other, ad infinitum, while SugarCube pushes you to separate each block through a page break or choices.
This section will use the {{{[[link]]}}} markup extensively, but you can use the {{{<<link>>}}} macro if you prefer. In most cases, they are [[interchangeable|Commands]]. This Markup/Macro can both create a choice and a page break, and is essentially the way to connect sections of the story together.
\
<h2>A Simple Page Break</h2>\
While SugarCube doesn't have a {{{*page_break}}} command, it is pretty simple to create a page break: a single link to a new passage.
{{{
→ ChoiceScript
Lorem Ipsum Lorem Ipsum Lorem Ipsum
*page_break
Lorem IpsumLorem IpsumLorem Ipsum
→ SugarCube
:: Passage1
Lorem Ipsum Lorem Ipsum Lorem Ipsum
[[Next|Passage2]]
:: Passage2
Lorem IpsumLorem IpsumLorem Ipsum
}}}
\
<h2>Simple Branching Choices</h2>\
If your story branches out into two or more distinct paths (at least for a section/passage), you can also use links to those new passages to send the players down those paths.
{{{
→ ChoiceScript
Lorem Ipsum Lorem Ipsum Lorem Ipsum
*choice
#choice1
*goto FirstPath
#choice2
*goto SecondPath
→ SugarCube
:: ChoicePassage
Lorem Ipsum Lorem Ipsum Lorem Ipsum
[[Choice1|FirstPath]]
[[Choice2|SecondPath]]
:: FirstPath
//Text of the First Path//
:: SecondPath
//Text of the Second Path//
}}}
\
<h2>"Fake" Choices</h2>\
Twine does not make a difference between a real and a fake choice when coding, only sending the player to a new section. It is still possible to emulate this "fake" choice with a combination of a link, some [[variables|Variables]], and a [[conditional statement|IfElse]].
{{{
→ ChoiceScript
Jolene taps her fingers on the desk, waiting for me to say something...
*fake_choice
#You stay silent.
I chickened out.
#You plead.
I couldn't leave without saying something.
She looked at me, concerned.
→ SugarCube
:: ChoicePassage
Jolene taps her fingers on the desk, waiting for me to say something...
[[You stay silent.|NextPassage][$silent to true]]
[[You plead.|NextPassage][$silent to false]]
:: NextPassage
<<if $silent is true>>I chickened out.<<else>>I couldn't leave without saying something.<</if>>
She looked at me, concerned.
}}}
\
<h2>{{{*selectable_if}}} Choices</h2>\
Similarly to ChoiceScript, SugarCube can displays //some// choices if the defined conditions are met, by using [[conditional statements|IfElse]].
{{{
→ ChoiceScript
For dinner, I think I'll have...
*choice
*selectable_if (chicken) #... chicken.
*goto EatChicken
#... nothing.
*goto NoEating
→ SugarCube
:: ChoicePassage
For dinner, I think I'll have...
<<if $chicken is true>>[[... chicken.|EatChicken]]<</if>>
[[... nothing.|NoEating]]
}}}
> ''Note:'' {{{*selectable_if}}} automatically greys out an unavailable option in ChoiceScript. In SugarCube, you will need to do this manually, by wrapping the "disabled" element in an {{{<span>}}} and adding styling. Like:
> {{{<span style="background:grey;">Disabled Text</span>}}}
> {{{<span class="disabled">Disabled Text</span>}}}
> with the latter being styled in the [[StyleSheet|JS-CSS]]
\
<h2>Reuse Choices</h2>\
While there are no comparable macros to the reuse commands in SugarCube, you can still emulate their functionalities by using [[conditional statements|IfElse]] to "disable" or hide choices. The difference between the two will be whether to add an {{{<<else>>}}} element to display the choice, but not allowing it to be selectable.
{{{
→ ChoiceScript
*label Dinner
For dinner, I think I'll have...
*choice
*hide_reuse #... chicken.
*goto Dinner
*disable_reuse #... more rice.
*goto Dinner
*allow_reuse #... extra sauce.
*goto Dinner
#... nothing more.
*goto Done
→ SugarCube
:: Dinner
For dinner, I think I'll have...
<<if $ateChicken is false>>[[... chicken.|Dinner][$ateChicken to true]]<</if>>
<<if $ateBeef is false>>[[... beef.|Dinner][$ateBeef to true]]<<else>>...beef<</if>>
[[... extra sauce|Dinner]]
[[... nothing.|Done]]
}}}
> ''Note:'' {{{*disable_reuse}}} automatically greys out an option in ChoiceScript. In SugarCube, you will need to do this manually, by wrapping the "disabled" element in an {{{<span>}}} and adding styling. Like:
> {{{<span style="background:grey;">Disabled Text</span>}}}
> {{{<span class="disabled">Disabled Text</span>}}}
> with the latter being styled in the [[StyleSheet|JS-CSS]]
\
<h2>Nested Choices</h2>\
Nested choices are also possible in SugarCube, though they will appear differently than in ChoiceScript. Rather than going to another page, the choice list will be replaced with the new text. Like with ChoiceScript, you can nest as many choices as you'd like (though by the 2nd-3rd nest, it may become difficult to keep track of the options).
> ''Note:'' refreshing the page after clicking on a nested choice will undo any change made, since Twine only saves when players move to a new passage.
\
To do this, you will need to use one of the more advanced macros: {{{<<replace>>}}}.
{{{
→ ChoiceScript
What do you want?
*choice
#A donut.
What flavour?
*choice
#Chocolate.
Too bad, here's a vanilla!
#Vanilla.
Too bad, here's a chocolate!
#Nothing.
K.
→ SugarCube
What do you want?
<span id="the-choice">
<<link "A Donut.">>
<<replace "#the-choice">>
A Donut.
What flavour?
<span id="the-taste">
<<link "Chocolate">>
<<replace "#the-taste">>
Too bad, here's a vanilla!
<</replace>>
<</link>>
<<link "Vanilla">>
<<replace "#the-taste">>
Too bad, here's a chocolate!
<</replace>>
<</link>>
</span>
<</replace>>
<</link>>
<<link "Nothing.">>
<<replace "#the-choice">>
K.
<</replace>>
<</link>>
</span>
}}}
:: Commands [commands] {"position":"900,300","size":"100,100"}
<h1>Commands vs Macros/Markup</h1>
To run bits of code, ChoiceScript will use commands, an instruction for the program that something other than displaying text will happen. It is formatted with an asterisk before the command wanted.
{{{
*command
}}}
Some commands only take one line (e.g. {{{*set}}}), while others will need multiple lines with indentation (e.g. {{{*choice}}}).
{{{
*set stat 35
*choice
#choice1
Text
*other_command
}}}
Twine, on the other hand, works with both macros and markup. Macros are similar to commands, in that they will tell the program that code must be run. Markup is a notation that will indicate [[styling|Formatting]], mainly used as a replacement for HTML.
Macros are formatted with {{{<< >>}}}, wrapped around the code.
{{{
<<macro [options]>>
}}}
There are two forms of macros: a one-block macro and a container macro. The one-block is self-explanatory (e.g. {{{<<set>>}}}), while the container is a two-block form, which can nest text, other macros, or both (e.g. {{{<<if>>}}}).
{{{
<<set $variable to 3>>
<<if $variable is 3>>
/* Something happens here */
<</if>>
}}}
\
One exception can be found with {{{<<link>>}}}, which can be both formatted as Macro and Markup, as well as mixed.
{{{
→ Markup:
[[Link]]
[[Text|PassageName]]
→ Macro:
<<link "Text" "PassageName">><</link>>
→ Mixed:
<<link [[Text|PassageName]]>><</link>>
}}}
The Markup form is particularly useful to quickly create links, as well as form visual connections between passages on the Twine app (an arrow will appear). The Macro form allows the inclusion of extra code to be run, such as setting variables only under certain conditions.
:: Credits {"position":"200,600","size":"100,100"}
This guide was constructed by ''manonamora''.
It is based on the SugarCube official documentation, created by Thomas M. Edwards, the developer of the SugarCube format, and the [[ChoiceScript Wiki|https://choicescriptdev.fandom.com/wiki/]].
<h3>manonamora</h3>\
You can find:
* my other templates on [[Itch|https://manonamora.itch.io/]], as well as my guides:
** [[SugarCube Guide|https://manonamora.itch.io/twine-sugarcube-guide]]
** [[Ready-to-Use Tweego and Guide|https://manonamora.itch.io/ready-to-use-tweego-folder]]
* my games and IF experiments on [[Itch|https://manonamora.itch.io/]]
* me, and ask me questions, over on [[Tumblr|https://manonamora-if.tumblr.com]] or [[my website|https://manonamora.neocities.org/]]
* my Twine Resource Masterlist on the [[IntFiction Forum|https://intfiction.org/t/twine-resource-masterlist-wiki/65903]] (a not updated version is rebloggable on [[Tumbr|https://manonamora-if.tumblr.com/post/700577877042888704/]]).
\
<h3>Twine and SugarCube</h3>\
[[About Twine and SugarCube|About]]
You can download Twine over on the [[Twinery.org|https://twinery.org/]] website, which includes the SugarCube format.
Thomas M. Edwards hosts the Documentation for the SugarCube format over on [[his website|https://www.motoslave.net/sugarcube/2/docs/]].
You can also find resources and help with Twine and SugarCube:
* on the [[IntFiction Forum|https://intfiction.org/c/authoring/twine/46]]
* on the [[Twine Subreddit|https://www.reddit.com/r/twinegames/]]
* in the [[Twine Discord|https://discord.gg/n5dJvPp]]
* and more listed in this [[Masterlist|https://intfiction.org/t/twine-resource-masterlist-wiki/65903]]
\
<h3>A Special Thanks to...</h3>\
* ''Chris Klimas'' for creating Twine, and ''TheMadExile/TME'' for making the SugarCube format and the Tweego compiler.
* ''Cycy'' for making the Twee 3 Language Tool extension for VScode.
* ''Brushmen'' for his [[Template|https://brushmen.itch.io/cs-like-sugarcube-template]]
* The Twine Discord!
* and Arlo, who read through the first version of this guide!
:: Formatting [commands] {"position":"900,700","size":"100,100"}
<h1>Formatting Text and Images</h1>
Compared to ChoiceScript, there is a lot more freedom to format your text in Twine. Because it allows HTML, you can essentially do anything a normal webpage would accept, whether it is bolding or italicise text, as well as changing colour and alignment, and even placement on the screen.
This section will cover the formatting Markup in SugarCube equivalent to the ChoiceScript commands. You can find the full list of formatting Markup in the [[SugarCube Documentation|http://www.motoslave.net/sugarcube/2/docs/#markup-style]].
\
<h2>Text Formatting</h2>\
While ChoiceScript uses a Markup similar to HTML to bolden or italicise text, SugarCube uses single quotes {{{'}}} and forward slashes {{{/}}}:
{{{
→ ChoiceScript
[b]Bold[/b] | [i]Italics[/i]
→ SugarCube
''Bold'' | //Italics//
}}}
\
<h3>Font, Colour, Size, etc...</h3>\
While ChoiceScript will let you change the formatting of the text in the StyleSheet, this will only apply to the whole of the game, rather than a small section. SugarCube will let you do both. You can change the overall look of the game in the [[StyleSheet|JS-CSS]], and specific smaller sections either in-line or in the StyleSheet. For the in-line styling, you can use the following markup:
{{{
@@style-to-edit;Text@@
@@color:red;Text@@
<span style="style-to-edit">Text</span>
<span style="color:red">Text</span>
→ with defined class/ID
@@#id;.class;Text@@
<span id="id" class="class">Text</span>
}}}
> ''Note:'' while the {{{@@}}} [[markup|https://www.motoslave.net/sugarcube/2/docs/#markup-custom-style]] can only create {{{<div>}}} or {{{<span>}}} elements, you can do in-line stylings with the {{{style=""}}} attribute for any HTML element (even {{{<p>}}}).
\
<h3>Headers and Lists</h3>\
Among the available [[markup|http://www.motoslave.net/sugarcube/2/docs/#markup-style]], you can also add headers and lists to your pages. Headers are created by preceding the text with exclamation points {{{!}}}, while lists will be done with either asterisk {{{*}}} (unordered) or hash {{{#}}} (ordered). The amount of characters used will determine how big/small a header is or how indented a list element is.
> ''Note:'' for both, the relevant markup character must be placed as ''the first character on the line'' - indented elements will break the styling.
{{{
!Header → <h1>Header</h1>
!!!!!!Header → <h6>Header</h6>
* Unordered List
** Indented Element
# Ordered List
## Indented Element
}}}
\
<h2>External Elements</h2>\
\
<h3>External Hyperlinks</h3>\
If you want to add a link to an external page, there isn't really a separate command like with ChoiceScript. You only need to create a link to that page, indicating the URL instead of the Passage's name:
{{{
→ ChoiceScript
*link https://www.website.com LinkName
→ SugarCube
[[LinkName|https://www.website.com]]
<<link "LinkName" "https://www.website.com">><</link>>
→ HTML
<a href="https://www.website.com">LinkName</a>
}}}
> ''Note:'' if you are creating this {{{[[link]]}}} on Twine, a new passage might appear with the URL as its name. You will need to delete that new passage, or the player will only see an empty page.
\
<h3>Displaying Images</h3>\
Just like ChoiceScript, you can add images to your project. You can use either the SugarCube markup or its HTML counterpart.
{{{
→ ChoiceScript
*image URL Alignment Alt-Text
*image image/wolf.png center A lone, mangy wolf howling at the moonlight.
→ SugarCube
[img[Alt-Text|URL]]
[img[A lone, mangy wolf howling at the moonlight.|image/wolf.png]]
→ HTML
<img src="URL" alt="Atl-Text">
<img src="image/wolf.png" alt="A lone, mangy wolf howling at the moonlight.">
}}}
> ''Note:'' while there isn't an alignment attribute, you can still style an image like you would a bit of text (see above).
\
While this isn't possible in ChoiceScript, you can turn an image into a link, either to another passage or to an external site:
{{{
[img[Alt-Text|URL-Image][URL]]
[img[A lone, mangy wolf howling at the moonlight.|image/wolf.png][https://www.website.com]]
<<link "<img src='URL' alt='Atl-Text'>" "URL/PassageName">><</link>>
}}}
> ''Note:'' be mindful of the order of quotes ({{{" ' ' "}}} or {{{' " " '}}}), or it will break the {{{<<link>>}}}.
\
<h2>Invisible Comment</h2>\
Like in ChoiceScript, you can add comments into your code with a special markup. These comments will be invisible to the player (unless they snoop in the code). You can also add comments to your StyleSheet and JavaScript section.
{{{
→ ChoiceScript
*comment a comment not seen by players
→ SugarCube Passage
/*a comment not seen by players*/
<!--a comment not seen by players -->
→ HTML/StoryInterface
<!--a comment not seen by players -->
→ JavaScript
//a comment not seen by players
/*a comment not seen by players*/
→ CSS/StyleSheet
/*a comment not seen by players*/
}}}
:: GoTo [commands] {"position":"900,600","size":"100,100"}
<h1>*goto for Calling Scenes and Endings</h1>
Because Twine and ChoiceScript are [[structured differently|Structures]], there are commands that are not translatable between the two formats. This is the most apparent with the {{{*goto}}} and {{{*gosub}}} commands, as well as {{{*finish}}} and {{{*ending}}}.
> ''Warning!'' SugarCube has a {{{<<goto>>}}} macro, which ''is not'' the {{{*goto}}} equivalent, because the player will be //''sent'' to a completely ''new'' page//. {{{<<goto>>}}} is like a link, without the required clicking.
\
The closest substitution for those {{{*goto}}} commands can be found with either the {{{<<include>>}}} macro or a customised {{{<<widget>>}}}. Instead of jumping to a specific line on the file, those macros will display the content of another Passage (for {{{<<include>>}}}) or of the widget. Thanks to this, you can call those macros at any point in the page.
> ''Note:'' you can also call those macros as many time as you want, in the same or different passages.
\
These are especially useful to display variations or run code that should be included in multiple sections of the game.
\
<h2>Using {{{<<include>>}}}</h2>\
The simplest way to create a {{{*goto}}}-like display is by using the {{{<<include>>}}} macro. For this, you will need two passages: the main one that the player will visit, and a second one which will include the text you want to display on the page or code you want to run.
{{{
→ ChoiceScript
*goto Next
{Some text/code}
*label Next
→ SugarCube
:: Passage
Lorem Ipsum...
<<include "SidePassage">>
Lorem Ipsum... with a choice?
:: SidePassage
Some text or maybe some code.
}}}
\
<h2>Using {{{<<widget>>}}}</h2>\
Widgets are slightly more complex, as it requires one special [[tag|Tags]] to define the macro. Like with {{{<<include>>}}}, you will need two passages: the main one that the player will visit, and a second one where you will define the widget. That second passage ''must'' have the tag {{{widget}}} attached to it.
> ''Note:'' you can define as many widgets as you want in that widget passage.
{{{
:: Passage
Lorem Ipsum...
<<SideSection>>
Lorem Ipsum... with a choice?
:: The Widgets [widget]
<<widget "SideSection">>
Some text or maybe some code.
<</widget>>
<<widget "ForLater">>
Another defined widget.
<</widget>>
}}}
\
<h2>{{{<<include>>}}} or {{{<<widget>>}}}?</h2>\
While the player will experience those two macros the same way, the macros are coded quite differently, as shown by the examples above. The main difference is in the way the macros use the side passage: {{{<<include>>}}} will use the whole, while {{{<<widget>>}}} only cares for what is defined inside its macro.
Another important point comes with namings. Since {{{<<include>>}}} require the name of a passage, that passage can include any characters, including whitespace and punctuation. On the other hand, {{{<<widget>>}}} is not bound to this, though it can ''only'' be named with the basic alphabet ({{{a → z}}}, {{{A → Z}}}) and numbers (anywhere ''except'' as the first character).
Finally, {{{<<widget>>}}} allows for extra customisation, such as passing parameters (i.e. indicating a variable or value) or turning it into a container. This essentially turns it into a customised macro. Since these are advanced options, see [[SugarCube Documentation|https://www.motoslave.net/sugarcube/2/docs/#macros-macro-widget]] for more details.
\
<h2>{{{*finish}}} a Scene</h2>\
While this command is essential to tell ChoiceScript to stop reading this particular scene and move on to the next one, this isn't needed in Twine games, because of the [[Passage Structure|Structures]]. If you want to move the player to a new section of the game, like a new chapter, you only need to create a link to a new passage:
{{{
[[End Chapter|Chapter85936759]]
<<link "End Chapter" "Chapter85936759">>
}}}
And, that's it.
\
<h2>Ending the Game</h2>\
As mentioned at the start, there is no equivalence to the {{{*ending}}} command to //End// the game, and include restarting or sharing buttons. In Twine, a game will end when the player has no other link to the progress the story further. This means that you will have more control over the customisation of this final page.
\
<h3>Restart the Game</h3>\
Unlike in ChoiceScript, you have two different ways to restart the game: with the {{{UI.restart()}}} API or a regular link sending the player back to the starting page. The first is the equivalent to the ChoiceScript //Play Again// choice, while the second allows the inclusion of a [[NewGame+|https://en.wikipedia.org/wiki/New_Game_Plus]] option.
> ''Note:'' using the passage [[functions|http://www.motoslave.net/sugarcube/2/docs/#functions]], like {{{hasVisited()}}}, is not compatible with NewGame+.
{{{
<<link "Restart">><<run UI.restart()>><</link>>
[[Restart|Start]]
}}}
> ''Note:'' you are not limited to a link, you can use the {{{<<button>>}}} macro instead.
\
<h3>Share the Game</h3>\
Twine does not have a specific script that will allow players to share the game on other platforms. If you want a specific //Share to [Platform]// link, you will need to create it yourself (or check for a plain HTML plug-in on the internet). Though, you are still free to add as many [[external hyperlinks|Formatting]] as you want (e.g. towards a promotional post on Tumblr).
:: IfElse [commands] {"position":"1000,500","size":"100,100"}
<h1>Displaying Variation and Conditional Statements</h1>
The logic behind Conditional Statements are pretty much the same between ChoiceScript and SugarCube, with the latter having a couple extra options.
{{{<<if>>}}} is a container macro, requiring a starting ({{{<<if>>}}}) and closing ({{{<</if>>}}}) element. Inside, you can add alternative conditions, with {{{<<elseif>>}}} and {{{<<else>>}}}.
{{{
<<if [condition]>>
/* Something happens */
<<elseif [condition]>>
/* Something happens */
<<else>>
/* Something happens */
<</if>>
}}}
Like its ChoiceScript counterpart, the {{{<<if>>}}} macro can do more than just display variation: set/modify variables, run code, make a choice/link (un)available, etc... It can also be nested inside other macros (including other {{{<<if>>}}}).
{{{
<<link "Check?">>
<<if $answer is true>>
<<goto "Next">>
<<else>>
<<goto "Fail">>
<</if>>
<</link>>
<<if $var is true>>
<<if passage() is "End">>
...
<</if>>
<</if>>
}}}
\
<h2>Basic Conditions</h2>\
Below, you will find a table with the different substitutes between ChoiceScript and SugarCube (TwineScript), as well as JavaScript, since SugarCube is based on it. For the full list of accepted TwineScript operators, see [[the documentation|http://www.motoslave.net/sugarcube/2/docs/#twinescript-operators]]
<<nobr>>
<table>
<tr>
<th>ChoiceScript</th>
<th>TwineScript</th>
<th>JavaScript</th>
</tr>
<tr>
<td>{{{*if (var1 = var2)}}}</td>
<td>{{{<<if $var1 is $var2>>}}}</td>
<td>{{{<<if $var1 === $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 != var2)}}}</td>
<td>{{{<<if $var1 isnot $var2>>}}}</td>
<td>{{{<<if $var1 !== $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 < var2)}}}</td>
<td>{{{<<if $var1 lt $var2>>}}}</td>
<td>{{{<<if $var1 < $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 <= var2)}}}</td>
<td>{{{<<if $var1 lte $var2>>}}}</td>
<td>{{{<<if $var1 <= $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 > var2)}}}</td>
<td>{{{<<if $var1 gt $var2>>}}}</td>
<td>{{{<<if $var1 > $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 >= var2)}}}</td>
<td>{{{<<if $var1 gte $var2>>}}}</td>
<td>{{{<<if $var1 >= $var2>>}}}</td>
</tr>
<tr>
<td>{{{*if var1}}}</td>
<td>{{{<<if $var1 is true>>}}}</td>
<td>{{{<<if $var1>>}}}</td>
</tr>
<tr>
<td>{{{*if not (var1)}}}</td>
<td>{{{<<if $var1 is false>>}}}</td>
<td>{{{<<if !$var1>>}}}</td>
</tr>
<tr>
<td>{{{*if (var1 = "words")}}}</td>
<td>{{{<<if $var1 is "words">>}}}</td>
<td>{{{<<if $var1 === "words">>}}}</td>
</tr>
</table>
<</nobr>>
Another couple of very useful operators in SugarCube is {{{def}}} and {{{ndef}}}, which will respectively check whether the variable is defined or not.
{{{
<<if def $var>>
/* Something happens */
<</if>>
<<if ndef $var>>
/* Something happens */
<</if>>
}}}
<h2>{{{<<elseif>>}}} and {{{<<else>>}}}</h2>\
If you have alternative variations that you want to display on the screen, or other code to run, you will use {{{<<elseif>>}}} for a defined condition and {{{<<else>>}}} for the rest. It works the same as with ChoiceScript.
{{{
→ ChoiceScript
*if (var < 30)
First variation?
*elseif (var < 60)
Second variation.
*else
The rest!
→ SugarCube
<<if $var < 30>>
First variation?
<<elseif $var < 60>>
Second variation.
<<else>>
The rest!
<</if>>
}}}
> ''Note:'' if you are using multiple conditions, be sure to order them from most to least restrictive. Otherwise, the wrong variation will be run.
\
<h2>{{{AND}}} and {{{OR}}}</h2>\
Like ChoiceScript, SugarCube uses both the {{{and}}} and {{{or}}} operators to add multiple conditions to one statement.
{{{
→ ChoiceScript
*if (var1 < 10) and (var2 <= 4)
*if (var1 < 10) or (var2 <= 4)
→ SugarCube (TS)
<<if $var1 lt 10 and $var2 lte 4>>
<<if $var1 lt 10 or $var2 lte 4>>
→ SugarCube (JS)
<<if $var1 < 10 && $var2 <= 4>>
<<if $var1 < 10 || $var2 <= 4 >>
}}}
> ''Note:'' while the examples do not have parentheses {{{ ( ) }}} around single conditions, those are recommended for operators like {{{def}}} and {{{ndef}}}. They will also be necessary for more complex statements:
> {{{<<if ($turn is 4 or $pet is "dog") && ($name is "Jane" or $credit gt ($cost * 2))>>}}}
\
<h2>What about Multireplace?</h2>\
While there is not special markup to create a Multireplace type of code, {{{<<if>>}}} is still the macro to use. While the examples above separated each condition from the variation and indented them, you can still use the macro in a single line:
{{{
I ate an <<if $var < 30>> apple? <<elseif $var < 60>> apricot. <<else>> orange! <</if>>
}}}
There is also the {{{<<switch>>}}} macro, which will do a similar thing, as long as the condition checks only one variable and defined values:
{{{
You <<switch $passed>>
<<case true>>passed
<<default>>failed
<</switch>> the test.
The man looks at you with <<switch $attitude>><<case 1>>hate<<case 2 3 4>>indifference<<case 5>>kindness<<default>>love<</switch>>.
}}}
For other use of the {{{<<switch>>}}} macro, see [[this page|Miscellaneous]].
:: Index {"position":"400,350","size":"100,100"}
<h1>Quick Equivalence Index</h1>
The index below will provide the closest equivalence of each ChoiceScript command in SugarCube (as best as possible) and the corresponding page.
> ''TLDR of the Guide:'' there's no 1-to-1 equivalence between the formats, only close approximation.
<<nobr>><table>
<tr>
<th>ChoiceScript</th>
<th>SugarCube</th>
<th>Guide</th>
</tr>
<tr>
<td>{{{*achieve}}}</td>
<td>N/A</td>
<td>[[Notes on Achievements|Achievements]]</td>
</tr>
<tr>
<td>{{{*achievement}}}</td>
<td>N/A</td>
<td>[[Notes on Achievements|Achievements]]</td>
</tr>
<tr>
<td>{{{*allow_reuse}}}</td>
<td>N/A</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*author}}}</td>
<td>{{{:: StoryAuthor}}}</td>
<td>[[Customising with Special Passages|SpeP]]</td>
</tr>
<tr>
<td>{{{*bug}}}</td>
<td>Debug Mode</td>
<td>[[Other Command Equivalents|Miscellaneous]]</td>
</tr>
<tr>
<td>{{{*check_achievements}}}</td>
<td>N/A</td>
<td>[[Notes on Achievements|Achievements]]</td>
</tr>
<tr>
<td>{{{*choice}}}</td>
<td>{{{<<link>>}}}/{{{[[link]]}}}</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*comment}}}</td>
<td>{{{/* comment */}}}</td>
<td>[[Formatting Text and Images|Formatting]]</td>
</tr>
<tr>
<td>{{{*create}}}</td>
<td>{{{<<set>>}}}</td>
<td>[[Variables: Types, Defining, Modifying and Deleting|Variables]]</td>
</tr>
<tr>
<td>{{{*delete}}}</td>
<td>{{{<<unset>>}}}</td>
<td>[[Variables: Types, Defining, Modifying and Deleting|Variables]]</td>
</tr>
<tr>
<td>{{{*disable_reuse}}}</td>
<td>{{{<<if>>}}}</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*else}}}</td>
<td>{{{<<else>>}}}</td>
<td>[[Displaying Variation and Conditional Statements|IfElse]]</td>
</tr>
<tr>
<td>{{{*elseif}}}</td>
<td>{{{<<elseif>>}}}</td>
<td>[[Displaying Variation and Conditional Statements|IfElse]]</td>
</tr>
<tr>
<td>{{{*ending}}}</td>
<td>N/A</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*fake_choice}}}</td>
<td>{{{<<link>>}}}/{{{[[link]]}}}</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*finish}}}</td>
<td>N/A</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*gosub}}}</td>
<td>{{{<<include>>}}}/{{{<<widget>>}}}</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*gosub_scene}}}</td>
<td>{{{<<include>>}}}/{{{<<widget>>}}}</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*goto}}}</td>
<td>{{{<<include>>}}}/{{{<<widget>>}}}</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*goto_scene}}}</td>
<td>{{{<<include>>}}}/{{{<<widget>>}}}</td>
<td>[[*goto for Calling Scenes and Endings|GoTo]]</td>
</tr>
<tr>
<td>{{{*goto_random_scene}}}</td>
<td>{{{<<include $var>>}}} (where {{{$var}}} has a random passage name)</td>
<td>[[Other Command Equivalents|Miscellaneous]]</td>
</tr>
<tr>
<td>{{{*hide_reuse}}}</td>
<td>{{{<<if>>}}}</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*if}}}</td>
<td>{{{<<if>>}}}</td>
<td>[[Displaying Variation and Conditional Statements|IfElse]]</td>
</tr>
<tr>
<td>{{{*image}}}</td>
<td>{{{[img[URL]]}}}</td>
<td>[[Formatting Text and Images|Formatting]]</td>
</tr>
<tr>
<td>{{{*input_number}}}</td>
<td>{{{<<numberbox>>}}}</td>
<td>[[Add Player Input and Interactivity|Input]]</td>
</tr>
<tr>
<td>{{{*input_text}}}</td>
<td>{{{<<textbox>>}}}</td>
<td>[[Add Player Input and Interactivity|Input]]</td>
</tr>
<tr>
<td>{{{*label}}}</td>
<td>{{{:: PassageName}}}</td>
<td>[[Understanding the Differences in Structures|Structures]]</td>
</tr>
<tr>
<td>{{{*line_break}}}</td>
<td>N/A</td>
<td>Just go to a new line.</td>
</tr>
<tr>
<td>{{{*link}}}</td>
<td>{{{[[link]]}}}/{{{<a>}}}</td>
<td>[[Formatting Text and Images|Formatting]]</td>
</tr>
<tr>
<td>{{{*page_break}}}</td>
<td>{{{<<link>>}}}/{{{[[link]]}}}</td>
<td>[[Having Choices and Linking Passages|Choices]]</td>
</tr>
<tr>
<td>{{{*params}}}</td>
<td>Through variables set in the choice</td>