Can you break this please


#1

This required some really complex coding and I’d really appreciate it if anyone could break it and then tell me how they did.

The Bug

Its 10 pages of starship troopers themed testery - so its not long

Thanks :bug:


The main code:

*goto start_linear

*comment CODE SECTION
*comment ==============================
*comment ==============================

*comment PURPOSE
*comment i) Move forward 1 page
*comment ii) Move forward more than 1 page
*comment iii) Move backward 1 page
*comment iv) Move backward more than 1 page
*comment v) Be able to ADD new pages without having to renumber pages (*label s)


*comment RETURN POINT FOR PAGES
*comment ========================================

*label start_linear
*comment (this starts the blank page run through)
*set pages_numbered false
*set reader_page_number 0 
*set true_page_number 0
*label after_pages_numbered
*if (pages_numbered = true)
  *comment *******************************
  *if (debug = true)
    *comment REMOVE THIS (***) before publishing
    *line_break
    Total reader pages
    *line_break
    ${reader_page_number_total}
*if (pages_numbered = true)
  *if (debug = true)
    page 0
    *comment *******************************
*comment β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
*label page_list
*if ((end_the_story = true) and (good_ending = false))
  That's right General Owen. You just wait here for rescue…
  *image General_Owen.png
  *sound Fleet-officials-admit-they-underestimated-the-Arachnids-defensive-capability.mp3
*if ((end_the_story = true) and (good_ending = true))
  You're going to try to stop me? You and what army?
  
  Good luck trying to decipher my mind code! 
  *image mind_reading.png
  *sound The-enemy-cannot-push-a-button-if-you-disable-his-hand.mp3
  *finish
*comment (ends the game)
*gosub check_choices
*comment (all 'pages' return here)
*comment (then get sent to *label go for page_numbering,)
*comment (and the choice to turn the page or skip elsewhere)
*gosub go
*if ((start_again_then_stop = true) and (pagevar_iv = 1))
  *set pagevar_iv 0
  *goto start_linear
*comment *******************************
*if (debug = true)
  *if (pages_numbered = true)
    True page number:
    *line_break
    ${true_page_number}
    *line_break
    Reader page number:
    *line_break
    ${reader_page_number}
    *comment *******************************
*set pagevar "t"&true_page_number
*if (pagevar_ii > 0)
  *set pagevar pagevar&underscore
  *set pagevar pagevar&pagevar_ii
*comment (this comment adds a double_space)
*gotoref pagevar

*comment INCREASES PAGE NUMBER, CONTROLS PAGE TURNING - GOSUB
*comment ====================================================

*comment Checks choices
*label check_choices

*return

*comment INCREASES PAGE NUMBER, CONTROLS PAGE TURNING - GOSUB
*comment ====================================================

*label go
*if (pages_numbered = false)
  *set reader_page_number + 1 
  *if (pagevar_ii = 0) 
    *set true_page_number + 1 
  *return
*if (pages_numbered = true) and (start_again_then_stop = false)
  *choice
      *if not (choices_phrase_i = "") 
        #${choices_phrase_i}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_two ""
          *set choices_correct_ii false
          *set choices_three ""
          *set choices_correct_iii false
          *set choices_four ""
          *set choices_correct_iv false
          *set choices_five ""
          *set choices_correct_v false
          *set choices_six ""
          *set choices_correct_vi false
          *gosub choices_record 
          *return
      *if not (choices_phrase_ii = "") 
        #${choices_phrase_ii}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_one ""
          *set choices_correct_i false
          *set choices_three ""
          *set choices_correct_iii false
          *set choices_four ""
          *set choices_correct_iv false
          *set choices_five ""
          *set choices_correct_v false
          *set choices_six ""
          *set choices_correct_vi false
          *gosub choices_record 
          *return
      *if not (choices_phrase_iii = "") 
        #${choices_phrase_iii}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_one ""
          *set choices_correct_i false
          *set choices_two ""
          *set choices_correct_ii false
          *set choices_four ""
          *set choices_correct_iv false
          *set choices_five ""
          *set choices_correct_v false
          *set choices_six ""
          *set choices_correct_vi false
          *gosub choices_record 
          *return
      *if not (choices_phrase_iv = "") 
        #${choices_phrase_iv}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_one ""
          *set choices_correct_i false
          *set choices_two ""
          *set choices_correct_ii false
          *set choices_three ""
          *set choices_correct_iii false
          *set choices_five ""
          *set choices_correct_v false
          *set choices_six ""
          *set choices_correct_vi false
          *gosub choices_record 
          *return
      *if not (choices_phrase_v = "") 
        #${choices_phrase_v}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_one ""
          *set choices_correct_i false
          *set choices_two ""
          *set choices_correct_ii false
          *set choices_three ""
          *set choices_correct_iii false
          *set choices_four ""
          *set choices_correct_iv false
          *set choices_six ""
          *set choices_correct_vi false
      *if not (choices_phrase_vi = "") 
        #${choices_phrase_vi}
          *comment (in story *choices have been replaced by *set_ting phrases that appear in this menu. And variables that are *set, then used to track the reader's previous choice, revealing the appropriate reading passage when they land on the story page)
          *gosub reset_choices_phrase
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *comment (this deletes the choices that weren't chosen before the one that was is recorded)
          *set choices_one ""
          *set choices_correct_i false
          *set choices_two ""
          *set choices_correct_ii false
          *set choices_three ""
          *set choices_correct_iii false
          *set choices_four ""
          *set choices_correct_iv false
          *set choices_five ""
          *set choices_correct_v false
          *gosub choices_record 
          *return
      *if ((((((choices_phrase_i = "") and (choices_phrase_ii = "")) and (choices_phrase_iii = "")) and (choices_phrase_iv = "")) and (choices_phrase_v = "")) and (choices_phrase_vi = ""))
        #Turn the page.
          *set reader_page_number + 1 
          *if (pagevar_ii = 0) 
            *set true_page_number + 1 
          *return
      *if (true_page_number > 1) #Flick back a page (or more).
        How many pages? (This is page ${reader_page_number})
        *set pagevar_viii reader_page_number
        *set pagevar_viii - 1
        *input_number pagevar_v 1 pagevar_viii
        *set pagevar_viii 0
        *set pagevar_iii reader_page_number
        *set pagevar_iii - pagevar_v
        *comment (finds new reader_page_number - then pages run through ex text again to regenerate correct true_page_number)
        *if ((pagevar_ii > 0) and (pagevar_v > pagevar_ii))
          *set pagevar_ii - pagevar_v
          *if pagevar_ii < 0
            *set pagevar_ii 0
        *comment (prevents issue with pagevar_ii preventing added pages being flicked back to)
        *set pagevar_v 0
        *set start_again_then_stop true
        *set pagevar_iv 1
        *comment (prevents issue with pagevar_ii preventing original pages being flicked back to after added pages)
        *set pagevar_ii 0
        *return
      *if ((true_page_number > 0) and (reader_page_number < reader_page_number_total)) #Skip ahead.
        To which page? (This is page ${reader_page_number})
        *set pagevar_viii reader_page_number_total
        *set pagevar_viii - 1
        *input_number pagevar_v reader_page_number pagevar_viii
        *set pagevar_viii 0
        *set reader_page_number pagevar_v
        *set pagevar_iii  pagevar_v
        *comment (finds new reader_page_number - then pages run through ex text again to regenerate correct true_page_number)
        *if ((pagevar_ii > 0) and (pagevar_v > pagevar_ii))
          *set pagevar_ii - pagevar_v
          *if pagevar_ii < 0
            *set pagevar_ii 0
        *comment (prevents issue with pagevar_ii preventing added pages being skipped forward to)
        *set pagevar_v 0
        *set start_again_then_stop true
        *set pagevar_iv 1
        *comment (prevents issue with pagevar_ii preventing original pages being skipped forward to after added pages)
        *set pagevar_ii 0
        *return
*if (pages_numbered = true) and (start_again_then_stop = true)
  *comment (this prevents a *choice occurring during a 'flick back' start_again_then_stop)
  *set reader_page_number + 1 
  *if (pagevar_ii = 0) 
    *set true_page_number + 1 
  *return


*label choices_record
*comment (this allows me to record the reader's choices)
*set choices_record choices_record&choices_one
*set choices_record choices_record&choices_two
*set choices_record choices_record&choices_three
*set choices_record choices_record&underscore
*set choices_record choices_record&underscore
*set choices_one ""
*set choices_two ""
*set choices_three ""
*return

*label reset_choices_phrase
*set choices_phrase_i ""
*set choices_phrase_ii ""
*set choices_phrase_iii ""
*set choices_phrase_iv ""
*set choices_phrase_v ""
*set choices_phrase_vi ""
*return

*comment THE LINEAR STORY: LIST OF PAGES
*comment ===============================

*comment (this allows the pages to be run through without text)

*comment β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-
*comment INSTRUCTIONS FOR CREATING AND LABELLING NEW PAGES
*comment β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
*comment 
*comment use '*gosub before_added' in the original page prior to the added page
*comment use '*gosub first_added' in the first added page
*comment use '*gosub second_added' (and so on)
*comment use '*gosub after_added' in the next original page
*comment 
*comment β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

*comment (t-check enables the activation of text after the initial no text pages are numbered, and after 'flick back's' start_again_then_stop) 
*label t_check
*if (pages_numbered = false)
  *set reader_page_number + 1
  *set reader_page_number_total reader_page_number
*set pagevar "t"&pagevar
*if ((pages_numbered = true) and (pagevar_iii = reader_page_number))
  *set start_again_then_stop false
  *set pagevar_iii 0
  *set pagevar true_page_number
  *set pagevar "t"&pagevar
  *if (pagevar_v > 0) and (pagevar_vi > 0)
    *set pagevar pagevar&underscore
    *set pagevar pagevar&pagevar_v
  *set pagevar_v 0
*if ((pages_numbered = true) and (start_again_then_stop = true))
  *set reader_page_number + 1 
  *if (pagevar_ii = 0) 
    *set true_page_number + 1  
  *comment *******************************
  *if (debug = true)
    True page number:
    *line_break
    ${true_page_number}
    *line_break
    Reader page number:
    *line_break
    ${reader_page_number}
    *line_break
    pagevar: ${pagevar_iii}
  *comment *******************************
*return

*label before_added
*set pagevar_ii 1
*set pagevar_vi 0
*return

*label first_added
*set pagevar_v pagevar_ii
*set pagevar_ii 2
*set pagevar_vi 1
*return

*label second_added
*set pagevar_v pagevar_ii
*set pagevar_ii 0
*set pagevar_vi 2
*return

*label after_added
*set pagevar_v 0
*set pagevar_vi 0
*return

*label t0 
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t1 
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t2
*gosub before_added
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar  

*label t2_1 
*gosub first_added
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t2_2 
*gosub second_added
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar

*label t3 
*gosub after_added
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t4
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t5 
*set pagevar_ii 1
*set pagevar_v pagevar_ii
*set pagevar_vi 0
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar  

*label t5_1 
*set pagevar_ii 0
*set pagevar_vi 1
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar 

*label t6 
*set pagevar_v 0
*set pagevar_vi 0
*gosub t_check
*if ((pages_numbered = true) and (start_again_then_stop = false))
  *gotoref pagevar   

*label t7 
*comment +++++++++++++++++++++++++++++++++++++
*comment LAST PAGE MECHANIC
*comment (cut and paste the (+++) into the last page)
*if (pages_numbered = false)
  *set pages_numbered true
  *comment (this finds the difference between true page number and reader displayed page number) 
  *set reader_page_number_total reader_page_number
  *set true_page_number_total true_page_number  
  *set true_page_number 0
  *set reader_page_number 0
  *set pagevar_v 0
  *page_break
  *goto after_pages_numbered
*comment (the above finishes the blank page run through)
*if (pages_numbered = true)
  *finish
*comment (the above allows the story to end despite the blank page run through mechanic)
*comment +++++++++++++++++++++++++++++++++++++


*comment THE LINEAR STORY: WRITING SECTION
*comment =================================

*label debug
pagevar = ${pagevar}
pagevar_ii = ${pagevar_ii}
pagevar_iii = ${pagevar_iii}
pagevar_iv = ${pagevar_iv}
pagevar_v = ${pagevar_v}
pagevar_vi = ${pagevar_vi}
reader_page_number_total = ${reader_page_number_total}
*return

*label tt0 
*if (debug = true)
  *gosub debug
*gosub_scene story tt0
*goto page_list

*label tt1 
*if (debug = true)
  *gosub debug
*gosub_scene story tt1
*goto page_list

*label tt2 
*if (debug = true)
  *gosub debug
*gosub_scene story tt2
*goto page_list

*label tt2_1 
*if (debug = true)
  *gosub debug
*gosub_scene story tt2_1
*goto page_list

*label tt2_2 
*if (debug = true)
  *gosub debug
*gosub_scene story tt2_2
*goto page_list

*label tt3 
*if (debug = true)
  *gosub debug
*gosub_scene story tt3
*goto page_list

*label tt4
*if (debug = true)
  *gosub debug
*gosub_scene story tt4
*goto page_list

*label tt5 
*if (debug = true)
  *gosub debug
*gosub_scene story tt5
*goto page_list

*label tt5_1 
*if (debug = true)
  *gosub debug
*gosub_scene story tt5_1
*goto page_list

*label tt6 
*if (debug = true)
  *gosub debug
*gosub_scene story tt6
*goto page_list

The writing file

*label tt0 

(Original page)

*return
*label tt1 

*image starship_troopers_logo.png
*sound And-I-know-its-my-choice-I-was-wondering-what-would-you-do-if-you-were-me.mp3

I created a mind game with six pages.

It didn't take long. But it was designed so a human could turn back a page to see what they'd just enjoyed. Or skip ahead to the good bits.

(Original page)

*set choices_phrase_i "Wow! Six pages!" 
*set choices_correct_i true
*set choices_one "tt1_choice_was_easily_amazed_or_snidely_sarcastic"
*set choices_phrase_ii "Yawning now…" 
*set choices_correct_ii true
*set choices_two "tt1_choice_is_easily_bored"

*return
*label tt2 

*if (choices_correct_i = true)
  Yes I thought that was very clever too.

*if (choices_correct_ii = true)
  Be patient you clot! Hmmm… I'm calculating that infesting your neural pathways will actually drop my IQ by 80 points…

  Anyway [i]I[/i] thought that I was being was very clever.
*gosub reset_all_choices
But afterwards I wanted to add a page. And this spawned a horde of mind-consuming bugs…  

How on Klendathu was I going add new pages? I'd already numbered all of the original ones!

(Original page)

*set choices_phrase_i "Please tell me this game isn't a massive and ill-conceived pun." 
*set choices_correct_i true
*set choices_one "tt2_I_am_a_misery_guts_and_don't_like_puns"
*set choices_phrase_ii "I [i]loved[/i] that film! Erm, I mean, I ironically love that film…" 
*set choices_correct_ii true
*set choices_two "tt2_choice_has_amazing_taste_in_movies_but_is_embarassed_about_it"

*set knowledge + 1

*return
*label tt2_1 

Surely adding new pages now will spawn even more bugs?

So I wracked my enormous brains and thought of a magic trick.

(Additional page)

*image magic_trick.png

*return
*label tt2_2 


I can tell people what page they are on. This, for instance is page ${reader_page_number}. But what if that’s all a brain-bug inspired illusion…

(Additional page)

*set choices_phrase_i "Huh?" 

*return
*label tt3 


Maybe while the reader thought they were on one page, they could truly be in another place entirely! 

The last page was actually page [b]tt2_2[/b]!

Tricking them like this could allow me to suck out all their Earth defence related secrets… Ahem. I mean, provide them with a pleasurable entertainment experience full of delightful options to flick back and skip ahead if they wanted to.

(Original page)

*set choices_phrase_i "You can't really suck information out of my brain!" 
*set choices_one "tt3_choice_you_can't_suck_my_brain!"
*set choices_correct_i true
*set choices_phrase_ii "This is reasonably impressive." 
*set choices_correct_ii true
*set choices_two "tt3_choice_this_is_reasonably_impressive"
*set knowledge + 1

*return
*label tt4

*if (choices_correct_i = true)
  *set knowledge + 3
  Oh but I can. This is what your little grey cells are telling me…

  ${choices_record}
*if (choices_correct_ii = true)
  Gosh. If you're that easily impressed I may not have to guide your actions with mind-altering substances at all…

  You'll be even [i]more[/i] impressed if you flick back a page and tell me I can't possibly read your mind with my disgusting mouth apparatus.

*gosub reset_all_choices

Writing the code was like building a fragile human city out of glass. It was just waiting for a bug meteorite to smash it to pieces.

I finally understood why the accepted universal truth of choicescript is 'keep things simple.'

But a great man from San Francisco once said,
*line_break
"come on you apes!! Do you want to live forever?!?!"

(Original page)


*return
*label tt5 


So I wrote a code that could:

i) Move forward 1 page
*line_break
ii) Move forward more than 1 page
*line_break
iii) Move backward 1 page
*line_break
iv) Move backward more than 1 page
*line_break
v) And allowed me to ADD an infinite amount of new pages without having to renumber pages to prevent the additional pages breaking the flick back / skip ahead mechanic.

(Original page)

*set choices_phrase_i "You're some sort of big, fat, smart-bug, aren't you?" 
*set knowledge + 1

*return
*label tt5_1 
*comment NO NASTY CODE HERE! MY, MY IT'S SO EASY TO PROOF READ!

Haha, don't be silly. I'm your friend. I have absolutely no agenda in trying amaze and distract your brain while I savour your mind juices.
    
Would you like to know more?

Of course you would…

vi) The last benefit is that the new code means simpler proofreading. 

The whole story is in one scene-file, without distracting bits of code, or leaps between large choice passages.

Military Intelligence (posing as a friendly editor) no longer has to read my mind to understand what I'd intended. Because now the story looks like this:

*image writing_page_example.png
*set knowledge + 1

(Additional page)

*return
*label tt6 
How do I know my mind game works?

Well it still turns pages and I didn't have to relabel them all. Plus:
 
vi) I've managed to suck all the information that I needed out of you. Future games will be even better targeted at your feeble human minds.

So maybe my code isn’t like a fragile human city waiting to be splatted at all! Maybe its more like an impregnable insect planet of evil.

Mwah-hah-hah.

So I invite you to send your space-fleet to try to break it… If you haven’t already tried - go ahead. 

Break my mind game. 

I dare you.

(Original page)

*fake_choice
  #I have to evade capture! Lives of the Federation are at stake.
    *set end_the_story true
  #We must meet this threat with our courage, our valor, indeed with our very lives to ensure that human civilization, not insect, dominates this galaxy [b]now and always[/b]!
    *set good_ending true
    *set end_the_story true  
*set knowledge + 1
*return




*comment ========================
*comment This resets all choices
*comment ========================
*label reset_all_choices
*set choices_correct_i false
*set choices_correct_ii false
*set choices_correct_iii false
*set choices_correct_iv false
*set choices_correct_v false
*set choices_correct_vi false
*return

#2

Maybe while the reader thought they were on one page, they could truly be in another place entirely!

The last page was actually page tt2_2!


I assume the β€œtt2_2” wasn’t intended.


#3

It was - but thanks for taking a look and pulling that up! (I should have made it clearer that was intentional! I have done now)

There are two page numbering systems, the first shows the reader what they expect (ie they flip a page and that increases by one). The second page numbering system is secret and accommodates added pages:

tt2_2:

t is a text marker (the game actually restarts and runs through all the pages without displaying text every time you flip back or skip forward)

tt (double t) represents a real text file - something that is going to show a chunk of the story (as opposed to the single t empty marker above

2 represents the hidden page-numbering systems β€˜true’ page number.

_2 represents the number of the additional pages added in between true page 1 and true page 2, this prevents disruption of the page-numbering (which is needed to make the skip forward and back functions work)


#4

I hope now it’s fine.
Can I ask what text editor do you use? Syntax of ChoiceScript mixes text with programming language-like constructs so it’s not that easy to bugfix when you have just black letters on a white background.
Notepad++? Vim? Sublime? Or maybe there is special ChoiceScript editor?


#5

I’m using mac default editor TextEdit. I’m guessing from your thread that you’re using something a bit more advanced…

@CJW has created a better tool for editing ChoiceScript, but I believe he’s waiting for permission to publish it :slight_smile:


#6

Alright - I think I’ve fixed the stats issue with stats not tracking when you skip forward and backwards.

That seems to be working now. So I’m gonna move this fella to my thread of minis…

To those who had a look, thanks very much! :wink: