I noticed no has done a post regarding dialogue between player and NPC, im sure it would help alot of people.
Does anyone have some advice for organizing a conversation between a player and npc in allegro.
Right now i have blue box made in photoshop that appears when i draw text on the screen. this occurence only happens once then im unable to have the player reply and so on.
for example://when enter is pressed goes to next line
NPC:HI How are you
press enter
Player: hello
press enter
NPC: go here
press enter
player: okay
can this be organized in simple if statement?
if (npc.boundx.boundy>player.boundx)//this is example I know how to code detection
{
al_draw_textf(line1)
}
then what if their are 4 lines
What you're probably looking for is a GUI(Graphical User Interface). You can try designing your own, or you can search for a good one with allegro support. TGUI is a nice one that comes to mind.
so allegro doesnt have any built in string management seems like i could
do
line1=aldrawtext(line1)
line2=aldrawtext(line2)
line3=aldrawtext(line3)
line4=aldrawtext(line4)
then
if (keys[ENTER])
for ( i=0; i<4;i++)
if(i>0)
line 1
if(i>1)
line2 and so on
it doesnt work though for some reason
i download tgui it seems cool, but outdated.also no tutorials or videos using it.
Is Guichan still a viable option? Edgar's working on a GUI lib, as well... There are so many GUI libraries that I lose track.
Arthur:
id prefer not to use a gui lib if possible how do i modify my if statement for it to display one line after the next upon pressing enter..
what is this hacker stuff?
There have actually been quite a few discussions here on this topic. You can try using the site search engine to find them, or use Google to search the site.
You don't need a gui, you just need a little more skill with C.
To carry on a conversation, you just need to use a little linked list that moves from one conversation event to another. Or if your conversation is linear and doesn't have any branches you could use a vector.
typedef std::list<const char*> CLIST; CLIST Conversation; conversation.push_back("Hello"); conversation.push_back("How are you"); conversation.push_back("Just fine thanks."); conversation.push_back("So on...");
CLIST::iterator cit = conversation.begin(); if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ENTER) { CLIST::iterator cit2 = cit; ++cit2; if (cit2 != conversation.end()) { cit = cit2; } }
You don't need a gui, you just need a little more skill with C++.
FTFY
In C you could do it like this (untested code):
Well, just to really confuse things, I do mine like this (I like each character to appear at a time, rather than whole lines); I use little codes in the string to decide what happens next, something like:
So basically I pick characters (like '¬' and '~') and use those as little codes in the string. This way I can have a whole multiline conversation, with delays/colour changes/prompts etc etc, that all look like:
"Welcome!...~010listen, I don't suppose¬you know where...~005...oh, nevermind!@"
"They say that ^082Mythril^255 is¬the strongest metal...~010¬bring me some ^020NOW^255!@"
etc etc...
My guess would be, just look at you're conversation as an automat or machine.
This would reduce the possibility dramatically.
PC can, quit, choose an item. You only have to organize this, which is a more or less sizeable problem.
Furthermore you can organize options as a tree. Each options spawns new options, which can be choosen or not.
It is rather a logic thing than an gui thing, IMHO.
FTFY
I just meant C in general, like C and C++ together.
This is what I was going to put up. It's a bastardization of C and C++. But there's a working example and source code.
NPC_conversation.7z
Just so we're clear on this, we're talking about a "window" that scrolls like a console? While using TTF fonts in A5 of course.
First off thanks for taking the time to reply ive been applying some of the ideas to my code trying to get them to work.
edgar: im getting an abortrun error saying vector-item-0 line 174 when running the main file.
*idk if this is relevant to the problem* when im looking through the zip in bittorrent.. when i click the npcexe saying im missing the libz.dll.
It's all I've got.
thanks edgar, nice code. I saved this in a word document and researching vectors a bit more so i can use this for my game.