intfiction.org

The Interactive Fiction Community Forum
It is currently Sat Nov 18, 2017 10:38 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Aug 29, 2017 11:36 am 
Offline

Joined: Mon Aug 28, 2017 11:55 am
Posts: 6
Hi All,

I'm looking to use a boolean variable to determine whether the user is currently allowed to go south or not. Below is the code I'm using.

Code:
After going south:
   if FightExamined is false:   
      instead of going south:
         say "Because you are still learning how to play the game, you are being prevented from going south just yet. After the tutorial you are free to move as you please.";


Elsewhere in my code I'm changing the boolean variable like this, which someone here has helped me with:

Code:
After examining the fight :
   now FightExamined is true;
   say "Variable FightExamined is [FightExamined]";


I have checked and this is working (I define the boolean variable earlier). The problem is that the first piece of code always prevents the user from going south. I want the user to move south once FightExamined is true.

Any help would be really appreciated!
Chris


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Aug 29, 2017 12:20 pm 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2467
Location: The Midwest
You're trying to nest rules inside each other, which doesn't really work. Try this:

Code:
Instead of going south when FightExamined is false: say "...".

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Aug 29, 2017 12:27 pm 
Offline

Joined: Fri May 31, 2013 3:54 pm
Posts: 100
EDIT: Ninja'd, here's what I was going to post!

The syntax "instead of going south" is redundant; Inform seems to be interpreting it as a completely new rule. You just want "instead":
Code:
After going south:
   if FightExamined is false:
      instead say "Because you are still learning how to play the game, you are being prevented from going south just yet. After the tutorial you are free to move as you please.".
But, since you're creating an "after" rule, this logic isn't applied until after the action. So you can still go south, it just replaces the usual report that's printed after the action. You probably want an "instead" rule:
Code:
Instead of going south when FightExamined is false, say "Because you are still learning how to play the game, you are being prevented from going south just yet. After the tutorial you are free to move as you please.".


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Aug 29, 2017 12:51 pm 
Offline

Joined: Sun Oct 11, 2015 5:09 pm
Posts: 276
The problem is not just with how you have written your rules. It's also that you're using an "after" rule. Any code that you put in an "after going south" rule will not, by definition, prevent the player from going south -- because the rule is not invoked until after the player has gone south.

It will, however, prevent the player from seeing the destination room description, because that happens in the "report" rules, and "after" rules supercede "report" rules by default. This can make it *seem* to the player that movement was prevented, even when it really wasn't.

For example, compile the following code and see what happens when you type "test me":

Code:
Test chamber is a room. 

After going south from Test Chamber:
   instead say "You are prevented from going to the other chamber."
   
Other Chamber is south of Test Chamber. "Oops, you're in the other chamber after all."

Test me with "s / look"


What you want is an "instead" rule. Instead rules prevent the action in question from actually occurring. Here's how you'd write it, along with a condition that makes sure the rule is only invoked when your boolean is false:

Code:
Instead of going south when FightExamined is false:
   say "Because you are still learning how to play the game, you are being prevented from going south just yet. After the tutorial you are free to move as you please."


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 3:48 pm 
Offline

Joined: Mon Aug 28, 2017 11:55 am
Posts: 6
Wow, thank you everyone for helping me out! I'll give this a try. What you say makes sense. I don't know if I'll ever get used to this higher-level language. It would be nice to use the nesting of rules, but I see the logic you're explaining. Thanks again everyone =]


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 5:52 pm 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2467
Location: The Midwest
If you're used to lower-level languages, think of rules as functions. A rulebook is simply a series of functions that run in order until one of them returns a value, at which point that's the return value for the whole thing. When I7 is compiled to I6, a rulebook literally becomes just a function that calls each rule in order. And a header like "Instead of..." or "After..." is just syntactic sugar for defining a rule and inserting it into a rulebook; you can also write "This is the foobar rule: say 'Foobar'. The foobar rule is listed in the Instead rules."

_________________
Daniel Stelzer


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 5:56 pm 
Offline

Joined: Mon Aug 28, 2017 11:55 am
Posts: 6
Ah gotcha, thanks! I was thinking of it more as an if statement.

On a related note, I can't see what is wrong with this:

Code:
NEnterPupilage is a number that varies.

After entering the Pupilage Basement Corridor:
   increase NEnterPupilage by 1;
   say "NEnterPupilage = [NEnterPupilage]";


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 7:26 pm 
Offline

Joined: Sun Oct 11, 2015 5:09 pm
Posts: 276
Assuming the Pupilage Basement Corridor is meant to be a room, then the action you want is "going". The "Entering" action is only called when the player attempts to enter a supporter or a container. (Attempts to enter a door are converted into a "going" action.)

Code:
After going to the Pupilate Basement Corridor:
   increase NEnterPupilage by 1;
   say "NEnterPupilage = [NEnterPuplage]";
   continue the action.


A couple of additional points:
  • The phrase "to the Pupilate Basement Corridor" is specific to rules involving the "going" action. It tests a local variable called "the room gone to". "After going to X" is equivalent to saying "After going when the room gone to is X".
  • Whenever you write an after going rule, you need to add "continue the action" at the end, or else the rule will prevent the room description from displaying when you arrive at the room gone to. (Because the rule to display the room description is in the report going rulebook, and the after rules supercede the report rules unless specifically told not to.)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 7:34 pm 
Offline

Joined: Mon Aug 28, 2017 11:55 am
Posts: 6
Ah so simple! Funny how it didn't error on me, but like so many languages I'm sure it has its own weird logic. Thanks!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 30, 2017 8:41 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5115
Location: Burlington, VT
It doesn't error because "entering" is itself an action--it's the action you'd do to get into an enterable container (ENTER BOX). So "entering the Pupilage Basement Corridor" is a valid description of an action, it's just not the action that's happening in this case. (Inform's default world model makes it pretty hard to get an action of entering a room to succeed, but it's grammatical.)


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group