Page 1 of 1

engine.dialogs.chat improvement

Posted: Sat Oct 09, 2010 1:50 am
by Lap
To have more diverse chats it helps to be able to have a bit more randomness similar to how resolvers work. Therefore I am proposing the following code change.

Normally we have this at line 76

Code: Select all

    if a.jump then
        self.cur_id = a.jump
However, with an easy change we get some more functionality.

Code: Select all

	if a.jump then
		if type(a.jump) == "function" then
		self.cur_id = a.jump()
		else
		self.cur_id = a.jump
		end
Now I can have an NPC preform very complex decision making to determine where the conversation goes, or more simply I can have him randomly spout off one of three lines of dialogue every time I ask him the same question.

Code: Select all

 jump = function() return "test" .. rng.range(1,3) end
Though I'm singling out a.jump I think all the fields could benefit from similar changes (text, action, cond).

Re: engine.dialogs.chat improvement

Posted: Sat Oct 09, 2010 2:00 am
by yufra
This came up before and there is a non-documented feature that the return value from the action function can actually provide the "jump" variable. The following example would randomly pick between the three possible chat options:

Code: Select all

action = function(player, npc)
    local possible_options = {"friendly", "neutral", "belligerent"}
    return rng.table(possible_options)
end
You could come up with a weighted rng.table that allows you to set weights for each particular option, but you get the idea. In regards to randomness in the action/cond/etc, well you can simply add randomness to the returns/brances of each. Define three action functions, action1, action2, and action3 and then do the following:

Code: Select all

action = function(player, npc)
    local possible_actions = {action1, action2, action3}
    return tng.table(possible_actions)(player, npc)
In summary, I think everything you want is already possible, just maybe not in the most elegant fashion.