Page 1 of 1

Can I control dialogue manually by script?

Posted: Mon Aug 22, 2016 12:29 am
by heyask
Dialogue System for Unity runs in auto continue with button click( next, next ..)

But can I load and show certain conversation line by code?

for example, there is 1 dialogue and 4 conversation.

example dialogue1
- hello1
- hello2
- hello3
- bye

show "hello1" by my script, after 3seconds, show "hello3", and after some process in my script, show "hello2" and "bye"

like this process!

because i have to put some "my script process" while dialogue in progress. script, conversation delay etc..


how can I do that with dialogue system for unity?

Re: Can I control dialogue manually by script?

Posted: Mon Aug 22, 2016 8:48 am
by Tony Li
Hi,

While it's possible to control the entire conversation manually, it's much easier to use a sequencer command to run your script process. This way you can use the other parts of the conversation framework instead of rewriting it yourself.

Here are the steps:

1. Copy Scripts/Templates/SequencerCommandTemplate.cs. Rename it to something like SequencerCommandMyScriptProcess.cs.

2. Edit the script. Remove the lines that say "[REMOVE]". Add your code in Start or Update. You can change Start to a coroutine if you prefer. When your script is done processing, make sure to call the method "Stop()".

3. Inspect the Dialogue Manager. Add MyScriptProcess() to the Display Settings > Camera Settings > Default Sequence field. For example, the Default Sequence might then look like this:

Code: Select all

Delay({{end}});
MyScriptProcess()
If you use a custom Sequence in any dialogue entry nodes (e.g., "hello2"), add MyScriptProcess() to it.

Each dialogue entry node will wait until the entire Sequence is done. (Or the Dialogue Manager's Default Sequence if Sequence is blank.)


If, on the other hand, you want to manually control the conversation, just let me know and I'll describe how to do it.

Re: Can I control dialogue manually by script?

Posted: Mon Aug 22, 2016 11:37 am
by heyask
Thank you for your reply.

I added custom SequenceCommand, but How can I access conversation nodes?

I looked for documentation http://www.pixelcrushers.com/dialogue_s ... mands.html

but I cant find function which can access conversation nodes, show nodes,
show second node, first node, third node etc..

I want to show conversation node randomly or else, so I need to access certain conversation node and show, not sequentially.
like, if there is 1~10 conversation nodes I need to show 6-7-3-5-2.... not 1-2-3-4-5.....


Would you show me some simple example code that how to access conversation node and show node?


And I found three functions that is GetParameter(0); GetSubject(); Stop(); I understand GetSubject(); Stop(); function, but what is GetParameter()? I don't know what parameters are send and from where?
GetParameter(0, 1, 2 ...); => Shows "Null" ? why?

Re: Can I control dialogue manually by script?

Posted: Mon Aug 22, 2016 10:11 pm
by Tony Li
Hi,

I put together three examples for you in this package:

heyask_Examples_2016-08-22.unitypackage


1 Custom Sequencer Command
This example demonstrates a custom sequencer command. I originally suggested custom sequencer commands because I thought you wanted to do processing before moving to the next node. I didn't realize you also wanted to change the order in which nodes were displayed. This example just shows how to write a custom sequencer command that's used in a node's Sequence field like this:
  • Sequence: Wait(3)
The example scene defines a new sequence command Wait(#), where the first (and only) parameter is the number of seconds to wait. This is just a re-implementation of the built-in Delay(#) command. It uses GetParameterAtFloat(0) to get the first parameter as a float value.


2 Random Order
This may be closer to what you're looking for. Instead of working with sequencer commands, it has a C# script that defines two simple Lua functions.

The first function, RandomNodeOrder(#), generates a randomly-ordered list of numbers.
For example, RandomNodeOrder(4) might generate a list { 3, 2, 4, 1 }.

The second function, GetNextNode() returns the next number in the list.

The example scene has a conversation titled "Random". The first node of the conversation calls RandomNodeOrder() and then x=GetNextNode(). Then it uses a group node as a hub. The group node links to several nodes. Each node has a Conditions field that checks the value of x, and a Script field that gets the next node number. Click on each node and read the Description field for more information.


3 Jump To Node
Rather than rewrite an existing example, I want to link you to the Backtracking Example on the Dialogue System Extras page. It adds support for backtracking conversations. To do this, it jumps the conversation to previous nodes.

Also refer to these discussions:
If I can provide any more assistance, just let me know.