Jump to content
Aveyond Studios Community
  • 0
disya75

Choises in dialogue

Question

10 answers to this question

Recommended Posts

  • 0

You can do this by doing the following:

  1. customize your dialog menu (the prefab) to contain the total number of choice options you want available. (each choice needs a game object)
  2. create a custom action based on Show Message. Modify the Add Choices field to accept more choices. You will also need to connect these new game objects to the new choices.

Try to build this, but if you get stuck, let me know. I'll have time this weekend to build something for you. 

Share this post


Link to post
Share on other sites
  • 0

Hello, Ant!
I tried to do everything myself, watched your video, but due to the fact that I'm not a programmer at all, it did not work for me (Unity constantly gives errors to different scripts) ... Now I'm completely confused and I really need your help!

I would be very grateful if you could create an action for me, allowing me to use my prefab, or simply explain in detail what and in which scripts needs to be changed.
Yours faithfully!

Here is the prefab of the dialog box I altered:

toAnt.jpg

Share this post


Link to post
Share on other sites
  • 0

@disya75, let's use these steps to add an extra button to the dialog box. If you need more buttons, just add more using the steps below.

Step 0: Download the two attachments at bottom of this post

  • While building this tutorial, I discovered there was some hard-coded stuff for the buttons in a core script. This has been fixed so that you can work with as many buttons as you want. The updated script (UIDialog.cs) is attached below. If you have HeroKit 1.11, you do not need to download this script, as it will appear in this version and greater versions moving forward.
  • I've attached a sample working project with four buttons. I built this tutorial as I built that project.
  • The attachments are in Unity Asset Files. If you download and click on these, the files will install into the proper locations in your currently open Unity Project.

Step 1: Create Your Dialog Box with Extra Buttons

Spoiler
  1. Open your game in Unity
  2. Open the Project tab
  3. Navigate to HeroKit > Hero Engine > Assets > Resources > Hero Templates > Menus
  4. Duplicate HeroKit Dialog Box A. Call the duplicate HeroKit Dialog Box B.
    • I would move the duplicate out of this directory and into this folder:
      [Your Game Name] (HeroKit) > Assets > Menus > Resources
  5. Drag HeroKit Dialog Box B into the Hierarchy.
  6. In the Inspector, mark the top-left checkbox to make the menu visible in the Game tab.
  7. In the Game tab, make sure you can see the dialog box.
  8. In the Hierarchy Tab, expand HeroKit Dialog Box B > DialogPanel > Layout > Dialog Box > Choice Buttons.
  9. Duplicate Choice Button 3. Change the name of the duplicate to Choice Button 4.
  10. Click on Choice Button 4.
  11. In the Inspector, expand the component called Hero Kit Listener UI and change the Item ID to 4 (it was 3).
  12. In the Hierarchy, expand Choice Button 4. You will see a gameobject called Choice Button 3 Text. Rename this to Choice Button 4 Text.
  13. In the Hierarchy Tab, click HeroKit Dialog Box B.
  14. In the Inspector, unmark the top-left checkbox and click the Apply button. The changes you made are saved in the prefab within your Project tab.
  • Delete HeroKit Dialog Box B from the Hierarchy tab (you don't need that one anymore now that you have your prefab updated).

 

 

 

Step 2: Attach Your Dialog Box to HeroKit

Spoiler
  1. Open any Hero Object.
  2. Click on the Settings Button (upper-right corner).
  3. Click on the button called Show/Hide Menu Templates.
  4. Drag your HeroKit Dialog Box B prefab from the Project tab into the field called Dialog Box.
  • Note: if you want to use both dialog boxes (HeroKit Dialog Box A, HeroKit Dialog Box B, you can alternatively use the Change Dialog Box action to swap these during gameplay.)

 

Step 3: Create a Custom Action for Show Message

Spoiler
  1. In the Project tab, navigate to HeroKit > Hero Actions > Core > Dialog Messages > Show Message.
  2. Duplicate Show Message (the action). Call the duplicate Show Message B.
    • I would move the duplicate out of the directory and into this folder:
      [Your Game Name] (HeroKit) > Assets > Hero Actions > Show Message 
  3. In the Project tab, navigate to HeroKit > Hero Engine > Actions > Core > Dialog and Language.
  4. Duplicate Show Message (the folder). Call the duplicate Show Message B.
    • I would move the duplicate out of this directory and into this folder:
      [Your Game Name] (HeroKit) > Assets > Hero Actions > Show Message
    • If you moved the duplicate as suggested above (both action and folder), they will both exist in the folder above.
  5. In the Show Message B folder, change the name of the ShowDialog script to ShowDialogB.
  6. In the Show Message B > Editor folder, change the name of the ShowDialogFields script to ShowDialogBFields.
  7. In the Project tab, select the action called Show Message B. The contents of that action appear in the Inspector. 
  8. In the Inspector, drag ShowDialogB into the Action field.
  9. In the Inspector, drag ShowDialogBFields into the Action Fields field.

 

Step 4: Modify the ShowDialogBFields script (add one button)

Spoiler
  1. Open ShowDialogBFields script in your IDE (Visual Studio or MonoDevelop).
  2. In this script, rename all instances of ShowDialogFields to ShowDialogBFields. (1 instance of it)
  3. Look for this line near the top of the script:
    ActionCommon.CreateActionFieldsOnHeroObject(heroAction, 35);
  4. Replace 35 with a 36.
    • If you want to add more than one button to your dialog box, increment this number for each new button. So if you are adding four new buttons using this tutorial, you would change this value to 39.
  5. Scroll down to the section where we store choices data. On line 135, add "Four" to the items array.
    
    string[] items = { "One", "Two", "Three", "Four" };
  6. Add a new results if statement for forth button.
    It's called (result > 3).
    Do you see the 35? This is the ID assigned to field assigned to the button. We are using a type of field called GetStringField. This is a field that you see on the Hero Object when you add this action to it. This particular field let's you type in a message for your button. Did you notice how we changed a previous parameter to 36 and we used a 35 here? This is no accident. When adding any new field, you must increase the number of fields available. Each field gets and ID, but be forewarned: you can't use the ID 36 if you only have 36 fields available. This is because fields start with the number 0, not 1.
    
    if (result > 0)
    {
        GetStringField.BuildFieldA("", actionParams, heroAction.actionFields[23], true);
    }
    if (result > 1)
    {
        GetStringField.BuildFieldA("", actionParams, heroAction.actionFields[24], true);
    }
    if (result > 2)
    {
        GetStringField.BuildFieldA("", actionParams, heroAction.actionFields[25], true);
    }
    if (result > 3)
    {
        GetStringField.BuildFieldA("", actionParams, heroAction.actionFields[35], true);
    }

     

  7. Save your changes. Now, when you open a Hero Object that contains this action, you will see that you can now select 4 buttons instead of 3. This is only half the battle though. Now you need to tell HeroKit what to do when there is a 4th button.

 

 

 

Step 5: Modify the ShowDialogB script (add one button)

Spoiler
  1. Open ShowDialogB script in your IDE (Visual Studio or MonoDevelop).
  2. In this script, rename all instances of ShowDialog to ShowDialogB. (4 instance of it)
  3. Scroll down to line 85 where we work with our buttons. Update the if (uiDialog.addChoices) statement to look like this:
    
    if (uiDialog.addChoices)
    {
        uiDialog.selectedChoiceID = 29;
        uiDialog.numberOfChoices = DropDownListValue.GetValue(heroKitObject, 22);
        uiDialog.choiceText = new UnityEngine.UI.Text[4];
        uiDialog.choice = new string[uiDialog.numberOfChoices];
      
        if (uiDialog.numberOfChoices >= 1) uiDialog.choice[0] = StringFieldValue.GetValueA(heroKitObject, 23, true);
        if (uiDialog.numberOfChoices >= 2) uiDialog.choice[1] = StringFieldValue.GetValueA(heroKitObject, 24, true);
        if (uiDialog.numberOfChoices >= 3) uiDialog.choice[2] = StringFieldValue.GetValueA(heroKitObject, 25, true);
        if (uiDialog.numberOfChoices >= 4) uiDialog.choice[3] = StringFieldValue.GetValueA(heroKitObject, 35, true);  
    }

    Notice that we added another if statement for 4 choices. 
    uiDialog.choice[] array is linked to the items[] array in the ShowDialogBFields script.
    Notice the 35 here? That's the ID we assigned to the field for our 4th button in ShowDialogBFields script.

  4. Save this file.

 

And your done! Give yourself a huge pat on the back! Try out your new action and let me know if it works. 

herokit-dialogbox-4-choices.unitypackage

herokit-uidialog.unitypackage

Share this post


Link to post
Share on other sites
  • 0

Hello , Ant!

Thanks so much for this amazing tutorial! I follow it step by step , but... Errors again 😞

HeroKit.Scene.HeroKitSettings must be instantiated using the ScriptableObject.CreateInstance method instead of new HeroKitSettings.
UnityEngine.ScriptableObject:.ctor()
HeroKit.Scene.HeroKitSettings:.ctor()
HeroKit.Scene.HeroKitCommonRuntime:GetHeroKitSettings() (at Assets/HeroKit/Hero Engine/Framework/4. Hero Common/Data/HeroKitCommonRuntime.cs:150)
HeroKit.Scene.HeroKitCommonRuntime:initializeGame() (at Assets/HeroKit/Hero Engine/Framework/4. Hero Common/Data/HeroKitCommonRuntime.cs:61)
HeroKit.Scene.HeroKitObject:Awake() (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:123)

and this:

NullReferenceException: Object reference not set to an instance of an object
HeroKit.Scene.HeroKitDatabase.GetAction (System.String key) (at Assets/HeroKit/Hero Engine/Framework/4. Hero Common/Data/HeroKitDatabase.cs:83)
HeroKit.Scene.HeroKitObject.PlayActions (Int32 eventID) (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:810)
HeroKit.Scene.HeroKitObject.PlayEvent (Int32 eventID, UnityEngine.GameObject messenger, Boolean useConditions, Int32 eventType, Int32 messageID) (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:762)
HeroKit.Scene.HeroKitObject.PlayEvents (Int32 eventType, Boolean useConditions, Int32 messageID, UnityEngine.GameObject messenger) (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:724)
HeroKit.Scene.HeroKitObject.Actions_Run_Once () (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:525)
HeroKit.Scene.HeroKitObject.ChangeHeroObject (HeroKit.Scene.HeroObject newHeroObject) (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:605)
HeroKit.Scene.HeroKitObject.Awake () (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:124)

-Unity 2017.1.0p5 , HeroKit - 1.10

What`s wrong? (

Share this post


Link to post
Share on other sites
  • 0

I've updated the tutorial. Can you start from the beginning? Before you do, make sure to install the two unity asset packages I've attached to the post. One of them is a core script that needed to be changed in HeroKit. The new version of that script will ship with the next version of HeroKit (1.11). 

Let me know how things go.

Share this post


Link to post
Share on other sites
  • 0

I install both packages and run your test scene , and Unity show that warning message:

HeroKit.Scene.HeroKitSettings must be instantiated using the ScriptableObject.CreateInstance method instead of new HeroKitSettings.
UnityEngine.ScriptableObject:.ctor()
HeroKit.Scene.HeroKitSettings:.ctor()
HeroKit.Scene.HeroKitCommonRuntime:GetHeroKitSettings() (at Assets/HeroKit/Hero Engine/Framework/4. Hero Common/Data/HeroKitCommonRuntime.cs:150)
HeroKit.Scene.HeroKitCommonRuntime:initializeGame() (at Assets/HeroKit/Hero Engine/Framework/4. Hero Common/Data/HeroKitCommonRuntime.cs:61)
HeroKit.Scene.HeroKitObject:Awake() (at Assets/HeroKit/Hero Engine/Framework/1. Hero Objects/Scene/HeroKitObject.cs:123)

But all works! Thanks for your help! :-)

Share this post


Link to post
Share on other sites
  • 0

@disya75, what version of Unity are you using? What version of HeroKit are you using? 

This message is directly tied to the new ability to save settings in the HeroKit settings menu. 

Can you open any HeroObject and click on the button in the upper-right corner? In theory, this warning should go away after you do this. If it doesn’t let me know.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×