0

I'm trying to increment a defglobal variable (symcount) by 1 if the user defines that they have pain by using the (read) function

(defrule QPain
         (initial-fact)
         =>
         (printout t "Are You In Pain? " crlf) 
         (bind (ans Answer) (read)) 
         )
(defrule AnsInc
         (Answ Answer = "y")
         =>
         (bind ?*symcount* (+ ?*symcount* 1))) 

the increment must only happen of the user presses "y" otherwise the increment must not happen.

Vox121
  • 181
  • 2
  • 9
  • possible duplicate of [How to compare a global variable to a string in Clips?](http://stackoverflow.com/questions/30324191/how-to-compare-a-global-variable-to-a-string-in-clips) – Gary Riley May 19 '15 at 16:31

1 Answers1

0
CLIPS> (defglobal ?*symcount* = 0)
CLIPS> 
(defrule QPain
   =>
   (printout t "Are You In Pain? ") 
   (bind ?answer (read))
   (if (eq ?answer y)
      then
      (bind ?*symcount* (+ ?*symcount* 1))))
CLIPS> (reset)
CLIPS> (run)
Are You In Pain? y
CLIPS> ?*symcount*
1
CLIPS> (reset)
CLIPS> (run)
Are You In Pain? n
CLIPS> ?*symcount*
0
CLIPS> 
Gary Riley
  • 10,130
  • 2
  • 19
  • 34