문제

While learning Prolog, I am writing a text-based game, this is some of it:

NewHealth is Health - Damage,
retract(stat(Target, health, Health)),
assert(stat(Target, health, NewHealth)),

I got an error about static procedures but a simple search fixed it, when running the game I would just quickly say dynamic stat/3. After that however, I get an error further up in the file where I declare the Health variable:

stat(Target, health, Health),

I narrowed down the problem to this (prolog console):

| ?- assert(test(a)).
yes
| ?- listing
test(a).
yes
| ?- dynamic test/1
yes
| ?- listing
yes

After being declared dynamic, it isn't in the static database anymore. But with a google search a couldn't find a case that has the same problem as mine. I just need to query and retract/assert a single database.

도움이 되었습니까?

해결책

dynamic/1 is a directive. Place it near to top of your file, with this syntax

:- dynamic stat/3.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top