Call function in script right at the moment when choices appear.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Spacepiratehacker54
Posts: 4
Joined: Tue Jun 20, 2023 2:18 pm

Call function in script right at the moment when choices appear.

Post by Spacepiratehacker54 »

Hi,
I would like to call a function with parameters (a string) of a script on a game object in the scene right at the moment when the choice menu appears, because I would like to instantiate a GameObject during the time the player is faced with the choice. How could this be realized? Thanks!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call function in script right at the moment when choices appear.

Post by Tony Li »

Use a sequencer command. You can write a custom sequencer command to call your function, or -- if the function accepts no parameters or a string parameter -- you can use the SendMessage() sequencer command. For example, if your function is on a GameObject named "Hourglass" and the function is named "Flip()", you could use the command:

Code: Select all

SendMessage(Flip, , Hourglass)
There are two points at which you can use the sequencer command:

1. At the end of the preceding dialogue entry's Sequence.
2. Or add a Response Menu Sequence to the preceding dialogue entry and use it there.

I'll go with #1 for an example. Let's say you don't require the player to click a continue button to advance the conversation. Instead, you want to advance to the response menu as soon as the subtitle panel's typewriter finishes typing. Then set the preceding dialogue entry's Sequence to:

Code: Select all

required SendMessage(Flip, , Hourglass)@Message(Typed)
The "required" keyword guarantees that the command runs even if the player skips ahead somehow.

door1Or2.png
door1Or2.png (26.05 KiB) Viewed 112 times
Post Reply