Community

SCI Programming => SCI Syntax Help => Topic started by: gumby on November 11, 2010, 10:50:52 PM

Title: Negation of Said()
Post by: gumby on November 11, 2010, 10:50:52 PM
I'm trying to test to see if something is NOT said.  Here is what I came up with:
Code: [Select]
(if(not Said('look'))
   Print("You did NOT type look")
)
...which works, sort of.  The problem is that the print statement is displayed for every keystroke & mouse click.  Once I finally get the text input box to show up (after many gyrations of keystrokes & mouse clicks), and I type 'look', the print message is not displayed, which is precisely what is desired.

Anyone got any ideas how to accomplish this correctly?
Title: Re: Negation of Said()
Post by: Cloudee1 on November 12, 2010, 11:30:17 AM
Adding a pevent claimed true should take care of it. I think.
Title: Re: Negation of Said()
Post by: MusicallyInspired on November 12, 2010, 03:19:54 PM
Fascinating. And yeah, I agree with Cloudee, seeing as it's not just looking for if you have "Said" something but any event covered under the handleEvent method...which is any input besides Saids as well.
Title: Re: Negation of Said()
Post by: Cloudee1 on November 12, 2010, 04:20:17 PM
Oh I see, I apparantly skimmed a little bit. I would start by hijacking troflips easy alt debugging to narrow the handleevent to just keystroke events, not mouseclicks. To get it further I would need to try it out myself.
Title: Re: Negation of Said()
Post by: gumby on November 12, 2010, 10:06:52 PM
I got it figured out.  At first glance I was skeptical of the no-claim direction, however:
Code: [Select]
(if(Said('*>'))
    (if(not Said('look'))
         Print("You did NOT type 'look'")
         (send pEvent:claimed(TRUE))
    )( else
(send pEvent:claimed(FALSE))    
    )
)
...sure seems to work!  So you start by doing a no-claim on *everything*, which gets you into a 'legitimate' user input (no mouse clicks/directional keys, etc).  Then just perform the event handling.  Works great.
Title: Re: Negation of Said()
Post by: gumby on November 15, 2010, 04:03:03 PM
Great.  So my above code does not work when you have more than one Said() negation in an if statement.  So I need an 'inline'/one-liner solution, similar to this (from my first post)
Code: [Select]
(if(not Said('look'))
   Print("You did NOT type look")
)
I was thinking about writing a procedure to do this, & use the said string as the parameter - but I never solved the problem in this thread here http://sciprogramming.com/community/index.php/topic,286.0.html (http://sciprogramming.com/community/index.php/topic,286.0.html) regarding dynamic said strings.
Title: Re: Negation of Said()
Post by: gumby on November 15, 2010, 09:15:22 PM
I'm an idiot... the post I referenced actually HELPED me solve the problem rather than stand in my way.  It must be one of those days.

Here is the complete solution:
Code: [Select]
(instance RoomScript of Script
(properties)
(method (handleEvent pEvent)
           (super:handleEvent(pEvent)

           (if(== NotSaid('look' pEvent) TRUE)
                 Print("You did not say LOOK!")      
           )        
  )
)

(procedure public (NotSaid saidStr pEvent)
   (if(Said('*>'))
       (if(Said(saidStr))
     (send pEvent:claimed(FALSE))
     return FALSE
       )( else
     (send pEvent:claimed(TRUE))
     return TRUE
       )
   )
)
Really straight-forward, no? 

EDIT:  Now that I look more closely at this, this isn't going to work for any word in the string that is inputted.  It will work for the first word only.  The procedure really ought to be named 'NotVerbSaid', or it should be retooled to go through every token in the Said(), not just the first.