I am writing a project in clips where I have some coordinated entities (squares of a board game). I define their templates like this:
(deftemplate square
(slot x (type INTEGER))
(slot y (type INTEGER))
)
So I want a function that can get a direction argument like right, left, up, down and the ?x, ?y coords and return the coords of the square lying in that direction (bordering the current one).
The problem is that functions can return a single value while I need both x, y.
I have tried
(return ?x ?y)
and
(return (?x ?y))
but they both give syntax errors.
is there a way to achieve that or I need to workaround it?
Thank you for your time.
Use create$ to place multiple values within a multifield value. You can then use nth$ to retrieve individual values:
CLIPS>
(deffunction direction ()
(return (create$ 1 -1)))
CLIPS> (direction)
(1 -1)
CLIPS> (nth$ 1 (direction))
1
CLIPS> (nth$ 2 (direction))
-1
CLIPS>