Markup Tag [position=#] is not working

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
r35
Posts: 5
Joined: Sat Apr 10, 2021 11:46 am

Markup Tag [position=#] is not working

Post by r35 »

Image

Not quite sure I'm using this markup correctly but what I'm trying to do is make the specific response always at the top.

It seems 'SetResponseButtons' is trying to order the buttons when there's a markup for the position

but buttons[] is empty at that point... :?

Is there any fix for this?
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Markup Tag [position=#] is not working

Post by Tony Li »

Hi,

The [position=#] markup tag doesn't apply to response buttons instantiated from the menu panel's response Button Template. It only applies to response buttons that you've assigned at design-time to the menu panel's Buttons list. (For example, see the Buttons list in the Wheel Standard Dialogue UI prefab, which has 6 design-time buttons.)

If you're using the Button Template to instantiate response buttons at runtime, you can use an OnConversationResponseMenu method to rearrange the Response[] array. For example, say you add a custom Boolean field named "Top" to your dialogue entry template, and you set it true for responses that should appear at the top of the list. Then your method might look like:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
     // Look for a response whose "Top" field is true:
     int topIndex = -1;
     for (int i = 0; i < responses.Length; i++)
     {
         if (Field.LookupBool(response[i].destinationEntry.fields, "Top") == true)
         {
             topIndex = i;
             break;
         }
     }
     
     // If we have one, put it at the front of the Response[] array:
     if (topIndex > 0)
     {
         var temp = responses[0];
         response[0] = responses[topIndex];
         responses[topIndex] = temp;
     }
 }
r35
Posts: 5
Joined: Sat Apr 10, 2021 11:46 am

Re: Markup Tag [position=#] is not working

Post by r35 »

Tony Li wrote: Mon Apr 26, 2021 10:11 am Hi,

The [position=#] markup tag doesn't apply to response buttons instantiated from the menu panel's response Button Template. It only applies to response buttons that you've assigned at design-time to the menu panel's Buttons list. (For example, see the Buttons list in the Wheel Standard Dialogue UI prefab, which has 6 design-time buttons.)

If you're using the Button Template to instantiate response buttons at runtime, you can use an OnConversationResponseMenu method to rearrange the Response[] array. For example, say you add a custom Boolean field named "Top" to your dialogue entry template, and you set it true for responses that should appear at the top of the list. Then your method might look like:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
     // Look for a response whose "Top" field is true:
     int topIndex = -1;
     for (int i = 0; i < responses.Length; i++)
     {
         if (Field.LookupBool(response[i].destinationEntry.fields, "Top") == true)
         {
             topIndex = i;
             break;
         }
     }
     
     // If we have one, put it at the front of the Response[] array:
     if (topIndex > 0)
     {
         var temp = responses[0];
         response[0] = responses[topIndex];
         responses[topIndex] = temp;
     }
 }
Got it, thanks for the solution!
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Markup Tag [position=#] is not working

Post by Tony Li »

Happy to help!
Post Reply