Useful Functions

version 1 by ShadowChaser

  • Home page
  • Beginning
  • Previous



  • Example: ** The Bridge of Death - A very basic example that makes use of most of the functions in this extension.

        "The Bridge of Death" by Shadowchaser

        Include Useful Functions By ShadowChaser.
        Include Basic Screen Effects by Emily Short.

        Use no scoring.

        The Bridge of Death is a Room. "You are standing in front of a rickety bridge traversing a huge gorge.".

        The rickety bridge is scenery in the Bridge of Death. The description is "It looks quite flimsy and can only take the weight of one person at a time.".

        The huge gorge is scenery in the bridge of death. The description is "This is the Gorge of Eternal Peril. It makes you shudder.";

        Approaching is an action applying to one visible thing.

        understand "approach [something]" as approaching.

        Instead of entering the rickety bridge, try approaching the rickety bridge.

        Carry out approaching:
            if the noun is not the rickety bridge begin;
                Say "That is not crossable.";
            else;
                let continue_val be 0;
                while continue_val is 0 begin;
                    clear the screen;
                    redraw status line;
                    say paragraph break;
                    let answer be yesno_answer_with_question "There is no turing back. Do you wish to continue (Y / N)?";
                    if answer is "NO" begin;
                        let continue_val be 1;
                        Say "Coward!";
                    else;
                        if answer is "YES" begin;
                            let continue_val be 1;
                            ask the questions;
                        end if;
                    end if;
                end while;
            end if.

        The answer_number is a number that varies. The answer_number is 0.
        The question_number is a number that varies. The question_number is 0.

        To ask_the_question:
            let continue_val be 0;
            while continue_val is 0 begin;
                clear the screen;
                redraw status line;
                say paragraph break;
                say "[question_text]";
                say paragraph break;
                let keypress be the key_pressed;
                if keypress is 49 begin;
                    let continue_val be 1;
                    now the answer_number is 1;
                else if keypress is 50;
                    let continue_val be 1;
                    now the answer_number is 2;
                else if keypress is 51;
                    let continue_val be 1;
                    now the answer_number is 3;
                end if;
            end while;

        To say question_text:
            if the question_number is 1 begin;
                say "The old man asks his first question:[paragraph break]";
                say "What is your name?[paragraph break]";
                say "Please type the number of your answer:[paragraph break]";
                say "1. King Arthur.[line break]";
                say "2. Good King Wencelas.[line break]";
                say "3. Elvis - The King.[line break]";
            end if;
            if the question_number is 2 begin;
                say "The old man asks his second question:[paragraph break]";
                say "What is your quest?[paragraph break]";
                say "Please type the number of your answer:[paragraph break]";
                say "1. To run through this stupid example.[line break]";
                say "2. To seek the holy grail.[line break]";
                say "3. I don't do quests.[line break]";
            end if;
            if the question_number is 3 begin;
                say "The old man asks his third question:[paragraph break]";
                say "What is the air-speed velocity of an unladen swallow?[paragraph break]";
                say "Please type the number of your answer:[paragraph break]";
                say "1. What do you mean? An African or European swallow?[line break]";
                say "2. What's an airspeed?[line break]";
                say "3. What's a swallow?.[line break]";
            end if.

        To ask the questions:
            Say "As you approach the bridge an old man appears and stops you. He stares at you with a baleful eye and says 'Who approaches the Bridge of Death must answer me these questions three, 'ere the other side he see.'[paragraph break]";
            pause_clear;
            ask_the_first_question.

        To ask_the_first_question:
            now the question_number is 1;
            ask_the_question;
            if the answer_number is 1 begin;
                award 1 point;
                Say "The old man says, 'Correct!'";
                say pause_clear;
                ask_the_second_question;
            else if the answer_number is 2;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                end_the_game;
            else;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                Say "A voice cries out 'Elvis has left the building!";
                end_the_game;
            end if;

        To ask_the_second_question:
            now the question_number is 2;
            ask_the_question;
            if the answer_number is 1 begin;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                end_the_game;
            else if the answer_number is 2;
                award 1 point;
                Say "The old man says, 'Correct!'";
                say pause_clear;
                ask_the_third_question;
            else;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                end_the_game;
            end if;

        To ask_the_third_question:
            now the question_number is 3;
            ask_the_question;
            if the answer_number is 1 begin;
                award 1 point;
                Say "The old man says, 'What? I don't know that!' An invisible force lifts him off his feet by and hurls him into the chasm below.";
                end_the_game;
            else if the answer_number is 2;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                end_the_game;
            else;
                Say "You are lifted off your feet by an invisible force and hurled into the chasm below.";
                Say "A voice cries out 'Elvis has left the building!";
                end_the_game;
            end if;

        Table of silly taunts
      rank  
      "You empty-headed food trough wiper."  
      "Your mother was a hamster and your father smelt of elderberries."  
      "Now go away or I shall taunt you a second time."  

        Table of silly_ranged_taunts
      maxpercent   rank  
      40  "I once more time-a unclog my nose in your direction, sons of a window-dresser!"  
      70  "I burst my pimples at you and call your daughter an unrequested silly thing."  
      100  "I wave my private parts at your aunties, you heaving lot of second-hand electric donkey bottom biters.";  

        To end_the_game:
            say paragraph break;
            say "You have answered [score percentage of 3] of the questions correctly.";
            say line break;
            say RangedRankOf score out_of 3 from_table Table of silly_ranged_taunts;
            say line break;
            say EqualRankOf score out_of 3 from_table Table of silly taunts;
            say line break;
            say "FYI the square root of 256 is [the square_root of 256].";
            if the score is 3 begin;
                end the game in victory;
            else;
                end the game in death;
            end if.

        Test me with "approach bridge".