I wonder whether anyone can help with a Ved problem?
I'm running my Eden (autonomous agent) simulation from inside Ved, by
calling
vedobey( 'FILE', simulate );
The simulator procedure goes round in a loop. At the start of each
cycle, it updates the edit window to display the current state of the
microworld. It then lets the agent "think", and updates the microworld
according to the agent's action, ready to be displayed on the next
cycle.
I am testing some code which allows the agent to behave
opportunistically, that is, to take advantage of events even if they
were not foreseen in its planning. For example, if a piece of "food"
suddenly appears, and the agent isn't too busy with other things, it
should grab and eat the food.
To exercise the opportunistic planner, I want to be able to deposit new
items in the microworld as the simulation runs. Since the microworld is
based on a 2d grid, one cell per character, the obvious way to do this
is to allow the user to edit the window, having the simulator then
read the changed buffer and update the world accordingly.
Here comes the problem. How do I invoke editing from inside a procedure
called by Ved? I thought that -edit(<filename>)- would do. According to
REF VEDPROCS, it "calls the editor with the file, whether in VED or
not". However, when I call it inside -simulate-, it immediately returns,
and doesn't allow the user to edit.
Secondly, even if I could invoke the editor, how would I redefine
a key temporarily? I need to redefine a key (haven't decided which one)
so that hitting it causes a return from editing, back to the simulator.
Incidentally, this key can't be ENTER, because I want the user to be able
to give ENTER commands from here.
I know one can imitate the Ved read-get edit proc-edit loop, and I could
do that if necessary. But I'd prefer a neater solution, especially as
I'm not sure that I could make my loop exactly imitate Ved's specification,
whatever that is.
A cut down version of the problem is below.
Jocelyn
;;; Main procedure. Call this to test.
;;;
define main();
vedobey( 'FILE', simulate );
enddefine;
;;; This procedure is run from inside Ved. It goes round in a loop,
;;; incrementing a counter and displaying it on line 10 of the edit
;;; window. At the end of each cycle, it asks the user whether he
;;; wants to change the counter. If he does, it calls -edit_file-,
;;; which lets him freely edit the window, putting a new value for
;;; the counter on line 9.
;;;
define simulate();
lvars c, counter = 0;
start:
vedputmessage( 'Next cycle' );
vedjumpto( 10, 1 );
vedcleartail();
vedinsertstring( counter><'' );
vedputmessage( 'Do you want to change the counter (y/n)?' );
vedinascii() -> c;
if c = `y` then
edit_file() -> counter
else
1 + counter -> counter;
endif;
goto start;
enddefine;
;;; This procedure is supposed to let the user edit the window being
;;; displayed. In this little example, he is assumed to be inserting
;;; an integer, the new value for -simulate-'s counter, at the start
;;; of line 9. -edit_file- will return this as its result.
;;;
define edit_file();
vedputmessage( 'Insert new value on line 9: press <some key> to finish' );
edit('FILE');
What I want here is some code which invokes Ved on the file
FILE and lets the user edit it freely. The only change from
normal is that <some key> should cause a return from
editing, transferring control back to the next line below.
This change in the effect of <some key> must be temporary,
because I want it to behave as normal at all other times.
Note: the obvious way to do this (modulo altering the <some
key> function) is to call
edit( 'FILE' )
at this point. However, if I do so, it immediately returns,
and doesn't allow the user to edit. Why?
vedjumpto( 9, 1 );
vednextitem();
enddefine;
|