intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Nov 16, 2018 6:27 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Check, Verify, Action
PostPosted: Tue Sep 04, 2018 8:03 pm 
Offline

Joined: Wed Feb 24, 2016 10:27 pm
Posts: 134
Hey,

I'm having a bit of trouble with dobjFor() macros on an Openable Booth. I have a basic idea of check and verify from reading. I'm trying to do a failCheck to report and skip action, but the action seems to be running any way. When I type open pen I get "seems like a waste of time."

Code:
sheepPen: Openable, Booth 'sheep pen*pens' 'sheep pen' @adamEveBarn
    isLocked = true
    isOpen = nil
    dobjFor(Enter)
    {
       
        check(){
            if(!isOpen)
            {
                failCheck('The pen is closed!');
            }
        }
       
         action(){"Seems like a waste of time";}
       
    }
     dobjFor(Open)
    {
       
         check(){
           
            if(!isLocked)
            {
                failCheck('The pen is locked!');
            }
            if(isOpen)
            {
                failCheck('The pen is open!');
               
            }
           
        }
       
        action(){"Seems like a waste of time";}
       
    }
   
;


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Sep 05, 2018 1:53 am 
Offline
User avatar

Joined: Tue Apr 20, 2010 2:48 pm
Posts: 1033
Location: Greece
This seems to contradict itself:

Code:
if (!isLocked) {
    failCheck('The pen is locked!');
}


Did you mean to use "if (isLocked)" instead?

_________________
@realnc


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Sep 05, 2018 10:48 am 
Offline

Joined: Wed Feb 24, 2016 10:27 pm
Posts: 134
Spot on RealNC. Thanks. Simple too.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Sep 06, 2018 4:01 am 
Offline

Joined: Sat Oct 17, 2015 5:48 am
Posts: 84
A simple debug trick: when there's a large set of if's nested or otherwise, is useful keeping different the responses, even when the same response makes sense; in the snippet above, there's two "seems like a waste of time", and changing one will point to the branching path followed.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Sep 06, 2018 10:52 am 
Offline

Joined: Wed Feb 24, 2016 10:27 pm
Posts: 134
Piergiorgio, you just inspired me. If I added a little logic to the other couldn't I cut back on code by calling one action as another? Is that what you mean?

Code:
sheepPen: Openable, Booth 'sheep pen*pens' 'sheep pen' @adamEveBarn
    isLocked = true
    isOpen = nil
    dobjFor(Enter)
    {
       
        check(){
            if(!isOpen || isLocked)
            {
                failCheck('The pen is closed!');
            }
        }
       
         action(){"Seems like a waste of time";}
       
    }
     
   Call Open -> Run Enter


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Sep 06, 2018 1:48 pm 
Offline

Joined: Sat Jul 16, 2011 3:48 pm
Posts: 309
Yes, you can remap one action to another like on the same object like:
Code:
    dobjFor(Push)
    {
        verify() {}
        action() { "Something... "; }
    }
    dobjFor(Pull) asDobjFor(Push)
    dobjFor(Move) asDobjFor(Push)

or remap action to another object (Learning T3 book, chapter 6.3.4):
Code:
    dobjFor(StandOn) remapTo(StandOn, subSurface)

or replaceAction or nestedAction from within action routine (after check/verify), chapter 6.3.7:
Code:
    dobjFor(Light)
    {
        verify() { nonObvious; }
        action() { replaceAction(Push, tabletButton); }
    }


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Sep 06, 2018 1:58 pm 
Offline

Joined: Wed Feb 24, 2016 10:27 pm
Posts: 134
Great, thanks tomasb.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Sep 08, 2018 3:33 am 
Offline

Joined: Sat Oct 17, 2015 5:48 am
Posts: 84
well, what I mean is that differentiating response gives an immediate check on actual branching path; for example, in your initial code, having, for example, "[open] seems like.. and "[enter] seems like.. will have shown immediately what path was followed, a substantial help in debugging logic operations.

OTOH, compacting the code reusing the same routines for different action is often the "right thing to do", albeit with large maximum story files available, tend to be a "lost art" (I'm rather slow in coding IF, and I have a "no vaporware" policy, but suffice to say that some WIP code here is still Inform 5/z3)

Best regards from Italy,
dott. Piergiorgio.


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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