Page 1 of 1

how to count the options in a dialog

Posted: Sun Jul 15, 2012 4:14 am
by Rickster
Hi,

is there a possibility to count the given options in a npc dialog?

there is a npc which, depending on some conditions, gives me other options to chose from and i want to react, based on the given options i can choose from.

e.g. what i want to know from a npc dialog is:

Code: Select all

What do you want to do?
I want this.
I want that.
I do not want anything.
how many options are there to chose from.

Thanx
Ric

Re: how to count the options in a dialog

Posted: Sun Jul 15, 2012 4:51 am
by lisa
Judging by Rock's ChoiceOptionByName() I doubt there is a count for options.

Can you just use the option by name??

ChoiceOptionByName("first text you want")
ChoiceOptionByName("second text you want")
ChoiceOptionByName("third text you want")


That will try first, second and third regardless of if any actually work.

In order to actually respond with inteligence then you will probably have to do something like this.

Wrote this in a bit of a hurry but hopefully you get the idea

Code: Select all

	optionnames = {}
    local counter = 1
	local option
    repeat
		option = RoMScript("GetSpeakOption("..counter..")")
		if option then
			table.insert(optionnames, option)
        end
        counter = counter + 1
    until not option
	
	for k,v in ipairs(optionnames) do
		if FindNormalisedString(v,"first choice") then
			RoMScript("ChoiceOption("..k..");"); yrest(1000);
			return
		end
		if FindNormalisedString(v,"second choice") then
			RoMScript("ChoiceOption("..k..");"); yrest(1000);
			return
		end	
		if FindNormalisedString(v,"third choice") then
			RoMScript("ChoiceOption("..k..");"); yrest(1000);
		end		
	end

Re: how to count the options in a dialog

Posted: Sun Jul 15, 2012 4:21 pm
by BillDoorNZ
you could try:

Code: Select all

GetNumSpeakOption();
havent' tried it myself, but thats what speakframe.lua uses

Re: how to count the options in a dialog

Posted: Mon Jul 16, 2012 1:09 am
by Rickster

Code: Select all

GetNumSpeakOption();

this does not work. mm shows this error:

Code: Select all

7:45am - [string "..."]:38: attempt to call global 'GetNumSpeakOption' (a nil value)
and i can not find something like this function in the wiki or in the forum

----------------------
[added] I used it the wrong way:

Code: Select all

counter = GetNumSpeakOption();
Look at lisas next post how to use it!
----------------------

i used part of lisas suggestion which i can use in a more simple way, as i only need to know if there are only two ore more options available

Code: Select all

local counter = 0;
local option;
repeat
	option = RoMScript("GetSpeakOption("..counter..")"); yrest(slow_time);
	counter = counter + 1;
until (not option or counter-1 > 2); -- stop if more then two options

if counter-1 > 2 then
	-- more than 2 options available
else
	-- 2 or less options available
end;
Thanx
Ric

Re: how to count the options in a dialog

Posted: Mon Jul 16, 2012 1:31 am
by lisa

Code: Select all

local counter = RoMScript("GetNumSpeakOption()")
if counter > 2 then
   -- more than 2 options available
else
   -- 2 or less options available
end
It doesn't count leave conversation as an option.

Re: how to count the options in a dialog

Posted: Tue Jul 17, 2012 1:48 am
by Rickster
that works great for me now :)

thank you all!

my mistake was to use GetNumSpeakOption() as a regular function not as a RoMScript.

btw ... where can I look for these RoM Functions?
Is there a wiki, like the wiki for this bot?

Ric

Re: how to count the options in a dialog

Posted: Tue Jul 17, 2012 1:49 am
by BillDoorNZ