Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » run an interpreter in an allegro game?

This thread is locked; no one can reply to it. rss feed Print
run an interpreter in an allegro game?
ratchet
Member #16,681
June 2017

My idea is to make a graphical text adventure in which the user interface is an interpreter/shell (the player character is a robot). In what I have so far, the game is loaded as a module in a Tcl interpreter. So there's one window running the interpreter and then another window with the allegro game. What I'd like to have is, inside the allegro game, a textbox running the interpreter.

could anyone tell me first of all whether this is possible and, if so, give me a general idea of how to go about doing it?

Thanks so much for any ideas.

SiegeLord
Member #7,827
October 2006
avatar

You could store your interpreter output in a string, and draw it using multiple calls to al_draw_string (once per line). Input can be handled via ALLEGRO_EVENT_KEY_CHAR events (see, for example, the ex_logo example).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

amarillion
Member #940
January 2001
avatar

You'd have to write your own textbox class, but this is certainly doable.

Your textbox class needs to keep track of the input string. Before the user presses enter, you have to build the input string, adding each keypress to it. You also have to respond to backspace by removing the last character from the input string.

If the user presses enter, you respond to that by passing the input string to the game engine.

ratchet
Member #16,681
June 2017

thanks for the replies. If I understand you both right, what you are explaining is how to get text input from the user and send it to the allegro display.

What I'm not understanding is how, on the one hand, you take the output from the interpreter and make it available to, for example, al_draw_string, or, on the other hand, how you take the string that you collect from ALLEGRO_EVENT_KEY_CHAR events and send it to the interpreter to be interpreted.

In other words, once you collect the user's key presses into a string, how do you get the interpreter to evaluate that string?

I hope I'm making sense.

SiegeLord
Member #7,827
October 2006
avatar

That's not really Allegro specific at this point, and depends on how your interpreter's API works. If you're using something like C++/Tcl then it could look something like this:

Tcl::interpreter i;

Tcl::object result = i.eval("some tcl command");

printf("%d\n", result.get<int>(i))

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

ratchet
Member #16,681
June 2017

Thanks, SiegeLord! C++/Tcl looks to be a very helpful suggestion. I'll check it out.

roger levy
Member #2,513
July 2002

I assume the API provides a function like FoobarEvaluate().

Go to: