How do I organize events / sets of actions to execute when play begins?

0 votes
276 views
asked Mar 26 in Authoring by Paul_Erdos (39 points)
edited Mar 30 by Paul_Erdos

How can I encapsulate stuff that I want to do when play begins? Can I structure an order of events to follow each other? Using 'when play begins' at different places in the text is unreliable, and is prone to executing out of order, or clearing things inappropriately. Even stringing scenes together at the start doesn't work. 

"Weird Stuff" by Writer.
Include Basic Screen Effects by Emily Short.
The player forename is some text that varies.
The player name is some text that varies.
To decide whether collecting names:
    if the command prompt is "What will your name be?  ", yes;
     no.

Gender is a kind of value. The genders are masculine, feminine, and unknown. 
Understand "male", "man", "boy" or "m" as masculine. 
Understand "female", "woman", "girl" or "f" as feminine.
A person has a gender. The gender of the player is unknown.

To decide whether the gender of the player is unknown:
    if the command prompt is "Are you male or female?  ", yes;
     no.

Prologue is a Scene. Prologue begins when play begins.
Prologue ends when Prologue Flag is zero.
Prologue Flag is a number that varies. Prologue Flag is one.
To End Prologue:
    Now the Next Flag is one;
    now the Prologue Flag is zero.
[I could set the next one to start when this ends]
[but that doesn't seem to stop the title / first room text from getting cleared]

Next Scene is a Scene. "I come next!" Next Scene begins when Next Flag is one.
Next Scene ends when Next Flag is zero.
Next Flag is a number that varies.
To End Next Scene: Now the Next Flag is zero.

When Prologue begins:
    display the boxed quotation "Fancy Title Box Text";
    show the current quotation;
    wait for any key;
    clear the screen;
    say "ominous introduction text";
    wait for any key;
    clear the screen;
    End Prologue.

When Next Scene begins: Now the command prompt is "What will your name be?  ";
    After reading a command when collecting names:
        now the player name is the substituted form of "[the player's command]" in title case;
        now the player forename is word number 1 in the player name;
        now the command prompt is "Are you male or female?  ";
        Reject the player's command;
        End Next Scene.

After reading a command when the gender of the player is unknown:
    if the player's command includes "[gender]":
        now the command prompt is "> ";
        now the gender of the player is the gender understood;
        if the gender of the player is masculine, now the player is male;
        if the gender of the player is feminine, now the player is female;
        wait for any key;
        Reject the player's command;
        End Next Scene;

Instead of looking when collecting names: do nothing.
Rule for printing the banner text when collecting names: do nothing.
Rule for constructing the status line when collecting names: do nothing.
Instead of looking when the gender of the player is unknown: do nothing.
Rule for printing the banner text when the gender of the player is unknown: do nothing.
Rule for constructing the status line when the gender of the player is unknown: do nothing.

Place is a room. "This might not show up, or it might show up prematurely!".

et cetera. There doesn't seem to be a concise way to end scenes with a statement, but that's another issue. This appears to remedy the order of the events, but it only goes so far. I can't seem to make more than a few events happen before the player is put in the first room.

Edit: Upon further review, I think I've found the culprit. The "reject the player's command" statements seem to screw with things that come afterwords. The "End Next Scene" doesn't work properly, possibly because of this. If I comment out the player input stuff, it all executes in order, and then the main title / room description shows up just fine.

commented Mar 26 by Ryan Veeder (290 points)
In the Paragraph Format drop-down of the submission interface (it says "Normal", which is the most average and unassuming paragraph format), you can select "Pre-formatted" to make your code display a little more pleasantly.
commented Mar 26 by Paul_Erdos (39 points)
I used the formatted option, and the double spacing made it look worse than this. I'll look again.
commented Mar 26 by AndrewS (250 points)
The sample code from "Identity Theft" seems to work okay for me in 6L02. How are you compiling it?

Also, your code seems to work ok when I build in the IDE on Windows. So I'm not sure how you're getting the reject message--"reject the player's command" should take care of it.
commented Mar 26 by Paul_Erdos (39 points)
I also have an input for gender, which if not entered properly, says the same "what are these verbs" thing, but that message isn't the main problem here: I can't get these things to happen without clearing some of the starting text.
commented Mar 27 by Paul_Erdos (39 points)
I suppose the problem could be generalized, doing any special startup stuff seems to interrupt the first bit of text printed, your titles and room descriptions and such.
commented Mar 27 by bg (692 points)
reshown Apr 2 by bg
Are you saying you want the name prompt, etc. to happen before the title banner and first room appear on the screen?
commented Mar 28 by Paul_Erdos (39 points)
edited Mar 30 by Paul_Erdos

So, this question, in a more general sense, is about the ordering of events, which I have recently learned is handled really well by scenes. For instance,

Prologue is a Scene. Prologue begins when play begins.

When Prologue begins:
display the boxed quotation "Title";
show the current quotation;
wait for any key;
clear the screen. Player survey is a Scene. Player survey begins when Prologue ends.
When Player Survey begins: Now the command prompt is "What will your name be? "; 

 

et cetera. There doesn't seem to be a concise way to end scenes with a statement, but that's another issue. I'll revise the question to reflect this.

commented Mar 30 by Paul_Erdos (39 points)
^ I accepted the answer, and then hid it because it wasn't a good solution, but it still showed that the question had a confirmed answer, which is weird.
commented Mar 31 by mattweiner (121 points)
Given your problem with "reject the player's command," it seems likely that the phrase "reject the player's command" causes the rule to stop running (looking at its definition in the Standard Rules, it seems to be invoking an Inform 6 command that causes the rulebook to fail, and when the rulebook fails the rule stops running right away). So the code after "reject the player's command" is just ignored.

A possible solution would be to put "End Next Scene" and "End Prologue" before "reject the player's command" in their respective rules.
commented Mar 31 by Paul_Erdos (39 points)
I did try that, but it still seemed to fall through and put the player on the map / start the game anyways.

I also noticed that having scenes start at the end of other scenes might be problematic for this same sort of rulebook-stopping thing, but it's avoidable by having a rule for ending scenes that turns on the new scene's flag before turning off the old one.

4 Answers

+1 vote
answered Mar 30 by bg (692 points)
edited Mar 30 by bg

I'm not sure if this will work for your situation, but I've done this kind of thing:

When play begins:
    cue the sound check;
    cue the prologue;
    [etc.]

To cue the sound check:
    [etc.]

To cue the prologue:
    [etc.]

In general, I tried to keep all but the most minor "when play begins" stuff in one section of the code, triggering various events from a single "when play begins" rule.

commented Mar 30 by Paul_Erdos (39 points)
Yeah, that's all well and good, and it WORKS, don't get me wrong. The issue I'm having is that the "reject the player's command" lines seem to cause the initial text to fall through / happen before it should. It MIGHT not be that particular command, but using scenes works perfectly, but dealing with player input for name and gender breaks it.
commented Mar 30 by bg (692 points)
My code above doesn't use separate scenes, at least not the way Inform understands scenes. But hopefully someone more experienced will be able to help you.
commented Mar 30 by Paul_Erdos (39 points)
The closest I've come so far is to nest each successive set of actions in the previous.

After reading a command when the gender of the player is unknown:
    if the player's command includes "[gender]":
            [start of what should be a scene, but is instead just a sloppily inserted set of commands]
            clear screen;
            say "Here's some dramatic text for the next scene."
0 votes
answered Mar 30 by bg (692 points)

One other idea: maybe it would make your life easier to use an extension for the text input.

http://inform7.com/extensions/Michael%20Callaghan/Questions/index.html

commented Mar 30 by Paul_Erdos (39 points)
I'll try that one out soon. It might be fancy packaging of the same methods I'm using, but maybe not.
0 votes
answered Mar 31 by mattweiner (121 points)

One thing about using "when play begins" rules in different places in the source text is that you can explicitly reorder the rules if they're running in the wrong order. Something like:

When play begins (this is the put things on the map rule):
...

When play begins (this is the make the map rule):
...
The make the map rule is listed before the put things on the map rule in the When Play Begins rulebook. 

Sometimes this can create unexpected results (the compiler goes through the "is listed before..." declarations in order and moves the appropriate rule so that it's satisfied, so it's not guaranteed that any individual declaration will still be respected after all the declarations are run. But with some trial and error (and use of the Rules tab of the Index to see what the order is) you should be able to get the rules in the order you want.

commented Mar 31 by Paul_Erdos (39 points)
Are these specific commands, "this is the put things on the map rule"? I can go in and find what those things are now that I know what to look for, but for the completeness of the question, you could use the real thing... and then I wouldn't have to do work... (:

(I'm pretending I'm concerned about the completeness of the answer because I don't want to have to go digging, but presumably, it'd be a good thing to do for people with this same problem in the future.)
commented Mar 31 by bg (692 points)
edited Mar 31 by bg
I'm pretty sure "this is the put things on the map rule" is a rule name mattweiner made up as an example. You can give names to rules using the syntax "(this is the x rule)" where x is pretty much any name you want (as in §19.3 in Writing with Inform). Then you can use "the x rule is listed before the y rule" to put them in order.
commented Apr 1 by mattweiner (121 points)
bg is correct--those are just example names for rules. Thanks for the link to §19.3, and §19.4 tells you about "listed before," "listed after," "listed first" etc. declarations.
commented Apr 1 by Paul_Erdos (39 points)
edited Apr 1 by Paul_Erdos
I'm a bit foggy as to how I should go about this. I can put things before play begins, but "when play begins" itself doesn't seem to contain any more discrete rules, so I don't really know what I'm replacing. Further, I'm not completely sure how to use scenes and rules together appropriately, but maybe that will clear up once I figure out the first part.

Edit: Even with the rules, it blows right through them!  I get to the command prompt change and waiting for input, and everything just goes! They're going in the right order, and I think they were before, but the input... maybe it's not stopping the rest of the stuff, and all the rules at the start just flash by after running the command prompt loop once, which I might be able to fix.
0 votes
answered Apr 1 by bg (692 points)
edited Apr 2 by bg

While this answer doesn't directly answer the main question ("How do I organize events / sets of actions to execute when play begins?") I think it addresses the issue that prompted that question: "I can't seem to make more than a few events happen before the player is put in the first room" and concerns about "clearing things inappropriately."

The final chunk of your code is (among other things) telling Inform not to print the banner text and not to look during the opening questions. (Looking is the action used to display the room name and room description when you enter a room.) So it's not that the title banner and room description are displaying and then getting cleared inappropriately--it's that they're being prevented from displaying in the first place. By the time the questions are finished, the usual moment for displaying the the title banner and initial room description has already come and gone, so they won't display at all unless you trigger them manually.

My guess is that it's not possible to ask a bunch of text input questions (at least, not the way they're set up here) before the first turn of the game, because the text input normally used for player commands is set up to happen in individual turns of the game. So rather than trying to squeeze in all the questions into that "when play begins" period (i.e. before the usual time when the title banner is displayed), I think what would work is to ask the questions in individual turns, but delay displaying the title banner and room description until the questions are finished.

Since your code already suppresses the title banner and initial room description during the questions, I just added in two lines to display the title banner and room description after the second question is answered.

I bracketed out the "wait for any key" line because I couldn't figure out its purpose and it seemed to delay the title banner. But maybe you just wanted a pause there.

I also altered the indentation, etc. of "When Next Scene begins: Now the command prompt is "What will your name be? " section, just because the indentation looked odd to me.

So, try this code and see if it does what you want. This doesn't address later additions/comments about the "reject the player's command" line (it looks like Next Scene doesn't actually end) but I hope it helps with the interruption issue.

Include Basic Screen Effects by Emily Short.
The player forename is some text that varies.
The player name is some text that varies.

To decide whether collecting names:
    if the command prompt is "What will your name be?  ", yes;
     no.

Gender is a kind of value. The genders are masculine, feminine, and unknown. 
Understand "male", "man", "boy" or "m" as masculine. 
Understand "female", "woman", "girl" or "f" as feminine.
A person has a gender. The gender of the player is unknown.

To decide whether the gender of the player is unknown:
    if the command prompt is "Are you male or female?  ", yes;
     no.

Prologue is a Scene. Prologue begins when play begins.
Prologue ends when Prologue Flag is zero.
Prologue Flag is a number that varies. Prologue Flag is one.
To End Prologue:
    Now the Next Flag is one;
    now the Prologue Flag is zero.
[I could set the next one to start when this ends]
[but that doesn't seem to stop the title / first room text from getting cleared]

Next Scene is a Scene. "I come next!" Next Scene begins when Next Flag is one.
Next Scene ends when Next Flag is zero.
Next Flag is a number that varies.
To End Next Scene: Now the Next Flag is zero.

When Prologue begins:
    display the boxed quotation "Fancy Title Box Text";
    show the current quotation;
    wait for any key;
    clear the screen;
    say "ominous introduction text";
    wait for any key;
    clear the screen;
    End Prologue.

When Next Scene begins: Now the command prompt is "What will your name be?  ";

After reading a command when collecting names:
    now the player name is the substituted form of "[the player's command]" in title case;
    now the player forename is word number 1 in the player name;
    now the command prompt is "Are you male or female?  ";
    Reject the player's command;
    End Next Scene.

After reading a command when the gender of the player is unknown:
    if the player's command includes "[gender]":
        now the command prompt is "> ";
        now the gender of the player is the gender understood;
        if the gender of the player is masculine, now the player is male;
        if the gender of the player is feminine, now the player is female;
        Say "[line break][the banner text]"; [* new line]
        Try looking; [* new line]
        [wait for any key;]
        Reject the player's command;
        End Next Scene;

Instead of looking when collecting names: do nothing.
Rule for printing the banner text when collecting names: do nothing.
Rule for constructing the status line when collecting names: do nothing.
Instead of looking when the gender of the player is unknown: do nothing.
Rule for printing the banner text when the gender of the player is unknown: do nothing.
Rule for constructing the status line when the gender of the player is unknown: do nothing.

Place is a room. "This might not show up, or it might show up prematurely!".
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...