1

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.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
DJRyan
  • 149
  • 2
  • 10

1 Answers1

1

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

:- dynamic stat/3.
CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • How is that different to just typing it in? – DJRyan Jul 15 '13 at 08:43
  • a directive is resolved at compile time (say, when Prolog loads your file). Now it's unclear to me *when* you type in, but probably, you mean at *runtime*. It's data, then... – CapelliC Jul 15 '13 at 08:45