[gameprogrammer] Re: designing an RPG dialog system
- From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 18 Jun 2009 08:20:46 -0700
Hey Roger,
I'm not sure how you have lua hooked up to the rest of your game but I too
am making an RPG powered by LUA and here's how dialogs work in mine.
I have a function UI_TextWindow with parameters like this:
UI_TextWindow(Text,FunctionOnClose);
when the player presses the button to close the dialog, it calls the
FunctionOnClose script function unless that value is "" (empty string)
also there are optional parameters on the end:
UI_TextWindow(Text,FunctionOnClose,Option1,Option1Function,......,OptionN,OptionNFunc);
so if the player chooses Option2 from the menu attached to the dialog, it
will call the script function Option2Func (unless the value is empty string
again...).
This works really well for us and the resulting Lua script is very simple to
create and read. Here's an example
-------------------------------------
--Dialogue_FortuneTeller_Scripts
-------------------------------------
--Dialogue_FortuneTeller_Intro1
-------------------------------------
function Dialogue_FortuneTeller_Intro1()
UI_TextWindow("Hi. I'm the Fortune Teller. I am going to ask you questions
some questions","Dialogue_FortuneTeller_Intro2");
end
-------------------------------------
--Dialogue_FortuneTeller_Intro2
-------------------------------------
function Dialogue_FortuneTeller_Intro2()
UI_TextWindow("Are you
strong?","","Yes","Dialogue_FortuneTeller_Intro2a","No","Dialogue_FortuneTeller_Intro2b");
end
function Dialogue_FortuneTeller_Intro2a()
UI_TextWindow("You are strong as a bear with the strength of two
bears!","Dialogue_FortuneTeller_Intro3");
end
function Dialogue_FortuneTeller_Intro2b()
UI_TextWindow("Weak? I hope you are a smart
one","Dialogue_FortuneTeller_Intro3");
end
-------------------------------------
--Dialogue_FortuneTeller_Intro3
-------------------------------------
function Dialogue_FortuneTeller_Intro3()
UI_TextWindow("What's your favorite
food","","Pizza","Dialogue_FortuneTeller_Intro3a","Chocolate","Dialogue_FortuneTeller_Intro3b");
end
function Dialogue_FortuneTeller_Intro3a()
UI_TextWindow("I love pizza too! It's my
favorite!","Dialogue_FortuneTeller_Intro4");
end
function Dialogue_FortuneTeller_Intro3b()
UI_TextWindow("I don't like chocolate. It makes me
fat","Dialogue_FortuneTeller_Intro4");
end
-------------------------------------
--Dialogue_FortuneTeller_Intro4
-------------------------------------
function Dialogue_FortuneTeller_Intro4()
UI_TextWindow("It was fun getting to know you!","");
Model_SetUseFunction(FortuneTellerModel,"Dialogue_FortuneTeller_Disappear1","Press
'E' to talk");
end
-----------------------------------
--Dialogue_FortuneTeller_Disappear1
-----------------------------------
function Dialogue_FortuneTeller_Disappear1()
UI_TextWindow("I don't believe in this stuff.
HAHAHAHAH","Dialogue_FortuneTeller_Disappear2");
end
On Thu, Jun 18, 2009 at 7:51 AM, Roger Durañona Vargas <luo_hei@xxxxxxxx>wrote:
> My pet project is an RPG, and I have advanced a little implementing a
> dialog system. The problem is that it is script based, using Lua, and
> each dialog needs to be manually edited. This is how the script looks
> (excuse me the long post, but this is the shortest dialog I have that
> illustrates at the same time the features i want):
>
> -- @param q Npc line number
> -- @param player Player entity
> -- @param npc NPC entity
>
> EM = EntityManager.EntityManager_getEntityManager()
> ent = EM:getEntity(player)
> npce = EM:getEntity(npc)
> -- get the game GUI
> gui = GuiSystem.GuiSystem_getGuiSystem()
> dm = DialogManager.DialogManager_getDialogManager()
> dm:reset();
>
> if (q=="root") then
> dm:setNPCLine("Bubbles, the official Calesoni alchemist at your
> service.")
> dm:addPlayerChoice("What do you do Bubbles?","question")
> dm:addPlayerChoice("Sorry, was just wandering around","end")
> elseif (q=="question") then
> dm:setNPCLine("I mix health and mana potions for the army. But
> mostly I distill the All-purpose potion.")
> dm:addPlayerChoice("All-purpose potion? And what is
> that?","question1")
> dm:addPlayerChoice("Ah, ok. Ill see you later.","end")
> elseif (q=="question1") then
> dm:setNPCLine("Alcohol, of course. It works as courage potion,
> for pain relieving and also to forget things.")
> dm:addPlayerChoice("I see. Can you teach me to distill alcohol
> and potions?","ask")
> dm:addPlayerChoice("Ill see you later.","end")
> elseif (q=="ask") then
> if (ent.stats[GameEntity.stINT]>12) then
> dm:setNPCLine("You seem to be smart. Look here, Im
> distilling some bottles, see?...")
> dm:addPlayerChoice("Yes, I follow you...","learn")
> else
> dm:setNPCLine("Sorry kid, you must finish the secondary
> school first.")
> dm:addPlayerChoice("Ok.","end")
> end --if int
> elseif (q=="learn") then
> dm:setNPCLine("And thats the basic. Did you got it?")
> dm:addPlayerChoice("Oh yes, thank you bubbles.","end")
> ent.skills:addSkill("Alch")
> gui:addMessage("You have learned Alchemy. You can improve it by
> practicing.")
> elseif (q=="end") then
> end
>
> I would like to hear suggestions and ideas to make it better, and
> perhaps some method that ease the task of editing them.
> Thanks in advance
>
> --
> Roger D. Vargas
> Gentoo Linux 2008.0
> http://gpnfn.blogspot.com, The news for game programming newbies
>
>
>
> ______________________________________________
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
Other related posts: