Page 1 of 1

i can't change variable in script

Posted: Wed May 12, 2021 10:25 am
by Yob
Hi.

i am working on random conversation.
so i want to change a variable in my script before starting conversation.
eg. script chooses one of characters randomly, and then starts conversation of first choosen character.

so i want to set variable at each character. and dialoguesystemtrigger's condition checks the variable.

but in my scripts it doesn't work.

"
public void putCharacter()
{

PixelCrushers.DialogueSystem.DialogueLua.SetVariable("who", names[who]);

gameObject.GetComponent<DialogueSystemTrigger>().OnUse();
who++;
"

above is my code.
names[who] is first character's name.

i am confused what is wrong. please help me!

Re: i can't change variable in script

Posted: Wed May 12, 2021 11:02 am
by Tony Li
Hi,

If you want to set a Dialogue System variable named "who", that code should work. To confirm, you can view the value of Variable["who"] in the Dialogue Editor's Watches tag at runtime.

I don't understand this part:
Yob wrote: Wed May 12, 2021 10:25 amscript chooses one of characters randomly, and then starts conversation of first choosen character.
How does the variable "who" relate to starting a conversation?

If you want to start a conversation from script, you can use DialogueManager.StartConversation(). Example:

Code: Select all

DialogueManager.StartConversation("Title", actorTransform, conversantTransform);
If you want a Dialogue System Trigger to start a conversation, you can change its conversation, conversationActor, and conversationCovnersant properties before using OnUse():

Code: Select all

var dsTrigger = GetComponent<DialogueSystemTrigger>();
dsTrigger.conversation = "Title";
dsTrigger.conversationActor = actorTransform;
dsTrigger.conversationConversant = conversantTransform;
dsTrigger.OnUse();
If you want to change the name used by an actor, such as the Player actor, before starting a conversation, set its Display Name field:

Code: Select all

DialogueLua.SetActorField("Player", "Display Name", names[who]);
dsTrigger.OnUse();

Re: i can't change variable in script

Posted: Thu May 13, 2021 3:21 am
by Yob
Thanks for good solution!

i need variable because i wanted to shuffle randomly and start its own conversation of each characters.
but your solution looks better.

i start conversation with your code.

DialogueManager.StartConversation("Title"); (i think Transform is not necessary)

i want to start at first default conversation such as 'greeting'
and i tried to execute function putCharacter() by scene event at the end of conversation .
(you can see the picture1)

public void putCharacter()
{
title = names[who];

DialogueManager.StartConversation(title);

who++;}

it is the function.
but it says that another conversation is already active. (picture2)

what can i do? if i want to run some conversation by script right after previous conversation?

thanks always!

Re: i can't change variable in script

Posted: Thu May 13, 2021 8:42 am
by Tony Li
I recommend linking your 'greeting' conversation to a different conversation for each character. Add Conditions that check the "who" variable. Before starting the greeting conversation, set the "who" variable. In fact, you don't even need the "who" variable if you specify the conversant GameObject. Example:

Code: Select all

DialogueManager.StartConversation("Greeting Conversation", player.transform, adam.transform);

Greeting Conversation:
who1.png
who1.png (16.04 KiB) Viewed 360 times

Linked conversations:
who2.png
who2.png (9.55 KiB) Viewed 360 times