Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Dialogue System for Unity - easy conversations, quests, and more!

Discussion in 'Assets and Asset Store' started by TonyLi, Oct 12, 2013.

  1. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Version 1.3.3 is live on the Asset Store now!
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Thought I'd mention that v1.3.3 introduces support for Animator Timeline Editor and Dark Tonic's Master Audio.

    If you're doing anything with audio, check out Master Audio. It's by far the most popular audio plugin on the Asset Store, available at an indie price but used by the big players like Zynga and Kings Isle. Just drop it in and you can duck audio (great for voiceover in conversations), controls playlists, and so much more.
     
    Keitaro3660 likes this.
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    50% Off Chat Mapper For A Limited Time!

    Pixel Crushers has negotiated a limited-time offer with Urban Brain Studios for Dialogue System customers. You can use coupon code PIXELCRUSHERS50SALE to get Chat Mapper Indie or Chat Mapper Commercial for 50% off. This coupon is good until September 22, 2014.

    Coupon Code: PIXELCRUSHERS50SALE

    Chat Mapper is a robust, industry standard dialogue authoring tool with some really great features, including:
    • A powerful, easy-to-use interface
    • A conversation simulator so you can quickly test your conversations before bringing them into Unity
    • An excellent screenplay exporter for voice actors
    • And more.
    If you have dedicated writers, Chat Mapper is a great way to give them a powerful authoring tool without having to learn how to use Unity. If you have voice actors, you can give them the type of screenplay format they're used to seeing. If you've been thinking of getting Chat Mapper for your project, now's the time.

     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    A quick reminder: When updating the Dialogue System to v1.3.3, please remember to also import any third party support packages, such as NGUI 3.x Support.
     
  5. gooberoo

    gooberoo

    Joined:
    Jun 3, 2014
    Posts:
    2
    Hi Tony it's me again just working through all of the features slowly but surely, love it so far! I was wondering if there's an easy way to make it so that a conversation reacts to variables changing during the actual conversation. Another way of putting it would be this- making it so that responses (and the "path" the dialogue takes) isn't based off a response menu, but a variable or integer that changes throughout the conversation based on external factors.

    An example would be if you wanted to make the player's response to an NPC random at every decision. Another example might be if a player could change their "state" throughout the conversation, which would affect the direction of the conversation.

    From what I can tell, the conditions for dialogue are determined at the beginning of the conversation, so changing the lua variable will not change anything until you start the conversation again. Obviously I could be wrong though, any ideas?
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    You can absolutely change Lua variables during conversations. The only thing to keep in mind is that the Dialogue System evaluates one step ahead. When the NPC prepares to speak a line, the Dialogue System also evaluates that line's links. If you use that line's Script field to change a Lua variable, it won't be noticed until the next line, because the links' Conditions have already been evaluated. If you need to work around this, just create an empty dialogue entry as an extra step between the NPC's line and the player's responses. In the Feature Demo, the "Private Hart" conversation does this with the Quick Time Event, and the "Terminal" conversation does this after inputting the password.
     
  7. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for this discount information on Chat Mapper. Is this discounted limited to a single copy or can you get more than one copy of Chat Mapper with this code? What type of upgrade cycle does Chat Mapper have? Since it is currently 1.7? Do you have to pay for upgrades when it goes from 1.7.x to 1.8 or is this from 1.x to 2.x? What is typical upgrade pricing in the past? If you purchase the indie version can you upgrade to the commercial version later?
     
    Last edited: Aug 19, 2014
  8. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for this new version. I will start looking at the new documentation soon. In previous sections of this thread there was mention of MS Excel spreadsheet support. Is this something that you are working on currently? Since Microsoft has made their file format open source it seems it could be easier to support now.

    http://blogs.office.com/2014/06/25/open-xml-sdk-goes-open-source

    https://github.com/OfficeDev/Open-XML-SDK

    Also there was mention of MySQL database support (wish list). Have you also looked at something like sqlite for a database? Since the source code is public domain and it is actively supported (and is used in many different products) it seems like something easier to support.

    http://www.sqlite.org
     
  9. Keitaro3660

    Keitaro3660

    Joined:
    May 20, 2014
    Posts:
    86
    wow nice information!!! :D
    hmmm... still wondering if i need this or not because i think my game dialog is not much, and chat mapper is too overwhelming. i'm fine using the default dialogue method :eek:
    but for the price cut of $30, and the probability of making more dialog in the future..
    yeah maybe, still got time to think until 22 sept :D
     
  10. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi longroadhwy, the discount code is good for unlimited orders but only a quantity of 1 per order. It applies to Indie and Commercial. Chat Mapper is a very mature product, so it doesn't require frequent changes. If I recall correctly, the developer releases an update approximately every 6 months. You don't have to pay for upgrades. As for upgrading from Indie to Commercial, I think you would have to arrange that specially with Urban Brain Studios.

    I opted for CSV import/export instead, since it's a general-purpose, text-based spreadsheet format that's compatible with more than just MS Excel. Chat Mapper, however, can import and export Excel.

    I'll have to leave that as an exercise for the reader. :) I'm trying to maintain a balance in the Dialogue System between being fully feature-complete and keeping it lean and efficient. If you want to store dialogue data in a MySQL database, you can export dialogue databases as Chat Mapper XML files and store them as text blobs in MySQL, pull them from the server as needed, and import the XML at runtime.
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    plyGame v2.2.3 was just released today. It contains an API change that requires an updated Dialogue System plyGame support package. You can download it on the customer download site or right here.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Now that the Unity 4.6 Public Beta is available, I'll be working on dialogue UI and bark UI implementations for the new GUI system. I'll release them as a patch on the customer download site as soon as they're ready!
     
    Parallaxe likes this.
  13. Keitaro3660

    Keitaro3660

    Joined:
    May 20, 2014
    Posts:
    86
    awesomeeee, keep the spirit! :D
    but how about the past dialogue UI? they're untouched and still available right?
     
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Absolutely! The other GUI systems will continue to be fully supported.

    Is anyone locked at their current version of Unity? The next Dialogue System release may require Unity 4.6 so it can use the new GUI system. If this will cause problems, please let me know!
     
    Keitaro3660 likes this.
  15. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Yes. I am locked to 4.5.2
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Okay, the minimum Unity version will remain at 4.3.4 through the end of the year. I'll include uGUI support as a separately-importable unitypackage for Unity 4.6 users.
     
    Parallaxe likes this.
  17. Keitaro3660

    Keitaro3660

    Joined:
    May 20, 2014
    Posts:
    86
    yup, i will still using 4.5.3 until unity 4.6 is fully functioning without bug,

    okay, i think that's the most win-win solution :D
     
  18. Alic

    Alic

    Joined:
    Aug 6, 2013
    Posts:
    137
    Hey, so I'm just playing around with this for the first time today. There's a ton of solid documentation but I've found it hilariously difficult to get the dialog system to behave like a basic, old fashioned console RPG -- I've been through all the demos and nothing has the behavior I'm looking for, not even the 2D Action RPG Starter Kit Integration Demo.

    I'm stuck on getting a simple one-node conversation to stay on screen until the player enters controller or keyboard input. It shouldn't require the cancel command, which can actually exit/interrupt dialogues, it should be a button that always advances a conversation unless it's completely over.

    Then, to get a little more picky, it would be great for it to work with the typewriter fast forward effect, the way the continue button fast forward component sounds like it does. So the first time you press the continue button, the text fast forwards or all pops up immediately, and then when you press it again the dialog moves to the next node.

    This behavior is so simple compared to what you've already got in there that it would be great to have one example that already does this. I've learned a decent amount about the system by digging around, but it would have solved all my problems to just see this already being done with the dialogue system. This tool seems like it started out focused on a very Mass Effect experience, but retro console RPG has gotta be a pretty common use case as well, right?


    Anyway, thanks for reading. And for all the work you've put into this asset! Really excited about the new unity GUI, it's awesome that you're already working on supporting it.
     
    Last edited: Aug 23, 2014
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi Alic, if I understand correctly, continue buttons will do exactly what you're looking for. There's an example scene in Examples/Feature Demo/Feature Demo with Continue Button. It uses a version of the Sci-fi Dialogue UI prefab that has continue buttons.

    If you're looking for a UI that's more like a console RPG, I added a continue button-enabled version of the JRPG UI to the next version of the Dialogue System. You can download it here and import it into your current project. Just assign this prefab to the Dialogue Manager's Dialogue UI, and set the Dialogue Manager's Subtitle Settings > Continue Button to the behavior you want (e.g., Always).
     
  20. Alic

    Alic

    Joined:
    Aug 6, 2013
    Posts:
    137
    That was ridiculously fast! So the continue button prefab works fine for me, but is it supposed to respond to keyboard input? Because for me it doesn't. Even if I check Navigation enabled on the continue button's GUIButton script, it still doesn't respond to the key chosen in the click field. Is there any quick way to get exactly the same behavior, but have it controlled by the keyboard and gamepad rather than the mouse clicking a button? And not even have to button be visible? Right now I want to try to achieve an interface that doesn't look like it wants a mouse at all.

    Thanks again Tony!

    *edit*

    Ah, I just figured it out.. on the GUIButton script, I didn't want the click or click button fields, I wanted the Key field under the Trigger category. Now it works great! This is just being picky, but is there a way to get the same function without having to have a GUIButton? Or maybe I should just hide the GUIButton?
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Just hide the GUIButton. Some developers make the button invisible (e.g., transparent texture) but also cover the whole screen so it registers as a button-click wherever the player clicks.
     
  22. Alic

    Alic

    Joined:
    Aug 6, 2013
    Posts:
    137
    cool, sounds good. Thanks Tony!
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The Dialogue System for Unity v1.3.4 has just been released! You can download it right away on the customer download site. (PM me your invoice number for access.) It should be available on the Unity Asset Store in a few days.

    Version 1.3.4:
    • Added: JRPG UI version with continue button.
    • Changed: QuestLogWindow and QuestLog.GetAllQuests() now sort alphabetically by quest title.
    • Changed: Barks now run the dialogue entry's Lua code and set the entrytag keyword.
    • Fixed: Localization of quest names.
    • Fixed: When trying to assign to a field of a nonexistent table element, LuaInterpreter would crash.
    • Fixed: Dialogue Editor no longer allows blank field titles in assets.
    • (PlayMaker, plyGame) Added: Set Language actions.
    • (Chat Mapper) Improved robustness of XML exporter for Chat Mapper's very specific import requirements.

    This release mainly provides fixes for some support issues.

    The top priority for development is support for the new UI. I'll make it available as a patch as soon as possible.
     
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Unity hadn't put v1.3.4 on the Asset Store yet, so I went ahead and submitted v1.3.4.1, which contains one more small feature request. If you've already updated to v1.3.4, there's no need to download v1.3.4.1 unless you're interested in these changes:

    Version 1.3.4.1:
    • Added: Localization option for Quest Trigger's alert message.
    • Fixed: Localized text table editor wasn't saving tables under certain conditions.
     
  25. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    A new video tutorial is available for Animator Timeline Editor support:
     
  26. JakeT

    JakeT

    Joined:
    Nov 14, 2010
    Posts:
    34
    Hi Tony - I'm going ahead and purchasing DSU now. Can you keep me posted on Twine integration? I'll get started with the built in system for now which will help.

    Also, very interested in 4.6 Unity GUI integration. I just spent the last couple days going through the new GUI tutorials and it's taking me seconds to do things that took days before. So I'll be excited to get DSU + Unity GUI fully integrated.

    Thanks!
    Jake
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi Jake, the Twine importer is "done," but I'm not 100% happy with it. It's difficult to represent all the information in a dialogue database in a Twine project. This is how imports are currently handled:
    • You'll need to create one Twine project for each conversation.
    • Passages are NPC/actor1 dialogue lines.
    • Links are PC/actor2 dialogue lines. You can use Twine's [[dialogueText|menuText]] format to set Dialogue Text and Menu Text differently.
    • Specify Sequences in double-bars (e.g., ||Camera(Closeup)||).
    • Put conditions on links using Twine's code syntax:
      Code (csharp):
      1. <<if expr>><<display menuText>><<endif>>
    • There's some basic translation of Twine script commands:
      • <<print expr>> is translated into Lua as [lua(expr)]
      • <<set $var = expr>> is translated into Lua as [lua(Variable["var"] = expr)]
      • Variables starting with "quest_" (e.g., quest_xyz) are translated into Quest["xyz"].State
    This has actually been implemented for some time now. I haven't released it because I'm not sure that it will allow you to do enough in Twine compared to what you can do with the built-in Dialogue Editor. If you or anyone else with more Twine experience has some suggestions, I welcome them.

    This will absolutely be in the next release, and available as a patch as soon as it's ready. Since you can swap UIs in and out, you can get started with the other aspects of the Dialogue System (dialogue content, triggers, quests, etc.) and temporarily use a legacy Unity GUI prefab or NGUI/DFGUI/TK2D if you have those products.
     
  28. TheNorthridge

    TheNorthridge

    Joined:
    Jan 4, 2012
    Posts:
    193
    Hey ToniLi! I just got UFPS, and found out your wonderful tool is compatible with it!

    Do you have any tutorials on how to get it set up and working?

    -Sean
     
  29. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Great! I think UFPS and the Dialogue System work pretty well together. They both support Oculus VR, too, if you're using that. Documentation is at: http://www.pixelcrushers.com/dialogue_system/manual/html/ufps.html -- there aren't any video tutorials yet. The "Shallow Integration" example is just a quick way to see the two products work together. In practice, you'll probably want to follow the instructions for "Deep Integration".
     
  30. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    Unity 4.6 new gui integration sounds good to me :)
     
  31. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    RPG Kit 2.1 integration tutorial:



    There's also an updated RPG Kit 2.1 support package on the Pixel Crushers customer download site. It adds a state machine action "Get IsConversationActive".
     
  32. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Will do. Technically it's already there, in the "RPG Kit 2.1 Support" package. In the next release, it's going to be packaged separately in "Third Party Support/AI for Mecanim Support". If you want to use it immediately, just import the "RPG Kit 2.1 Support" package and delete the RPG Kit 2.1-specific files.
     
  34. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    No we will wait for it to be its own support package. Good to hear.
     
  35. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The Dialogue System for Unity v1.3.4.1 is now available on the Asset Store!

    Version 1.3.4.1:
    • Added: Localization option for Quest Trigger's alert message.
    • Fixed: Localized text table editor wasn't setting dirty bit.
    (Version 1.3.4:)
    • Added: JRPG UI version with continue button.
    • Changed: QuestLogWindow and QuestLog.GetAllQuests() now sort alphabetically by quest title.
    • Changed: Barks now run the dialogue entry's Lua code and set the entrytag keyword.
    • Fixed: Localization of quest names.
    • Fixed: When trying to assign to a field of a nonexistent table element, LuaInterpreter would crash.
    • Fixed: If a Dialogue Editor template field has a blank title, it will not be added to assets.
    • Fixed: Link priorities were not being observed.
    • (PlayMaker, plyGame) Added: Set Language actions.
    • (Chat Mapper) Improved robustness of XML exporter for Chat Mapper's very specific import requirements.


    The Pixel Crushers office will be closed September 20-30.
    I'll try to check support emails daily, but Internet access might be spotty while I'm traveling.

     
  36. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Hi Tony,

    I'm having a issue using the latest version of ChatMapper and the dialogue system. Whenever I use a condition in ChatMapper for conditionally displaying a dialog choice the condition isn't validated. For instance: Dialog[6].SimStatus == "WasDisplayed"
    Within the Chat mapper simulator everything works fine however in Unity only those choices are displayed without any condition specified (even if the condition is met). Any suggestion?
     
  37. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi cygnusprojects, starting in version 1.3.0, the Include Sim Status checkbox defaults to unticked. The majority of users weren't using SimStatus, and many of them wanted to be able to conserve Lua memory. If you tick this checkbox, the conditions should start working. If the issue continues, please let me know.
     
  38. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    A new NGUI support package is available for the Dialogue System. You can download it here or on the customer download site. (PM me your invoice number if you need access.) It includes:
    • NGUI Selector Display component that lets you use NGUI with the Selector or Proximity Selector.
    • A fix to response buttons that was required by newer versions of NGUI.
    • Rebuilt basic dialogue UI prefabs that use NGUI’s new prefab editing method.
    This package will also be in the next full release of the Dialogue System.
     
  40. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
  41. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    I'll look into it! You can currently use BioWare's Aurora Toolset, which is the predecessor to the Dragon Age toolset and is almost identical in most ways. Instructions are here. One studio used Aurora to write over 500,000 words of dialogue and quests, localized in two languages, and then brought it all into Unity using the Dialogue System.
     
    Last edited: Sep 9, 2014
  42. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    The plyGame API changed in version 2.2.6, breaking the Dialogue System's support scripts for plyGame. You can download an updated support package here or on the customer download site.
     
  43. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    766
    Working fine now with the checkbox enabled! Thanks.
     
  44. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Great! Sorry about the confusion. I try to avoid changes like this that might affect existing projects. But if I need to make one, I'll always include a bold note in the release notes and post it on this thread, too.
     
  45. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    This Dorkly comic, Why RPG NPCs Always Repeat Themselves, reminded me how repetitive NPC barks can be. In the Dialogue System, it's really easy to give NPCs more variety.

    First, use the RandomElement() Lua function. Some examples:
    • Dialogue Text: Hi! [lua(RandomElement("Nice|Wonderful|Chilly|Brisk"))] weather today, isn't it?
    • Dialogue Text: [lua(RandomElement("Hello.|Nice to see you.|Good day.|Yo!"))]
    These will produce barks such as "Hi! Wonderful weather today, isn't it?" and "Yo!".

    Or, for a more advanced example:
    • Variable["Greets"]: Greetings|Salutations|Hail
    • Actor["Player"].Honorifics: Great|Esteemed|Bold|Worthy
    • Actor["Player"].GenderTitles: Sir|Master|Lord|Knight
    • Dialogue Text: [lua(RandomText(Variable["Greets"]))], [lua(RandomText(Actor["Player"].Honorifics))] [lua(RandomText(Actor["Player"].GenderTitles))]!
    This will produce barks such as "Greetings, Bold Knight!" and "Salutations, Esteemed Master!".

    If you want barks to be sensitive to the state of the world, use conditions:
    • Define a variable "IsDaytime". When it's daytime in the game, set it True. When it's night, set it False.
    • Bark 1:
      Conditions: Variable["IsDaytime"] == true
      Dialogue Text: Good day to you!
    • Bark 2:
      Conditions: Variable["IsDaytime"] == false
      Dialogue Text: Good evening, [lua(RandomText(Actor["Player"].GenderTitles))].

    Or use the built-in relationship system.
    • Bark 1:
      Conditions: GetRelationship(Actor["Husband"], Actor["Player"], "love") > 0
      Dialogue Text: I drew you a bath, dear wife. Just follow the rose petals!
    • Bark 2:
      Conditions: GetRelationship(Actor["Husband"], Actor["Player"], "love") < 0
      Dialogue Text: Go away, you hag. I'm watching the game.
     
  46. RaiuLyn

    RaiuLyn

    Joined:
    Sep 14, 2014
    Posts:
    39
    Hi TonyLi,

    I have been trying to figure out how to implement random response choices in conversations for a while and seeing how RandomElement() is mentioned. Is it possible for Conversations to do the same?
     
  47. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi RaiuLyn, yes, absolutely. There are two ways you can randomize conversations:


    1. Randomize the text used in a line. For NPC lines, you can do the same thing with Dialogue Text as in my previous post. You can also use RandomElement() to add random elements to the player's response text. For example, one of the first responses that the player can choose in the Feature Demo conversation with Private Hart is:

    Menu Text: Calm down. What's the problem?

    You can change this to:

    Menu Text: [lua(RandomElement("Calm down.|At ease, private.|Yes, soldier?"))] What's the problem?

    One time through the conversation, the response might be: "Calm down. What's the problem?". Another time, the response might be: "Yes, soldier? What's the problem?"


    2. Randomize the available branches. To do this, set a variable, perhaps using the math.random() function in a dialogue entry's Script field. (Make sure you're using Dialogue System 1.3.3+. The math library wasn't automatically loaded in v1.3.0 - 1.3.2.) Then check that value in later dialogue entries' Conditions fields.

    The Dialogue System evaluates one level ahead, so if you set the variable in one node, you should check it at least two levels down, not in the direct child nodes. For example, Private Hart's conversation has a QTE in his "I won't do it, sir." line. There's an intermediate node "QTE check" (in green below) to separate this node from the "Oof!" node that plays if the QTE is triggered. If that intermediate node wasn't there, the "Oof!" node's condition would be checked too early and it wouldn't work.



    The screenshot above is from the upcoming version, which shows the active conversation flow at runtime. Version 1.3.4.2 and earlier don't have this feature. The upcoming version also lets you set runtime watches on Lua variables and expressions.
     
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Reminder:

    The Pixel Crushers office will be closed September 20-30.
    I'll try to check support emails daily, but Internet access might be spotty while I'm traveling.

    By the end of this week, I'll release a support package for the new UI in Unity 4.6 beta.
     
  49. RaiuLyn

    RaiuLyn

    Joined:
    Sep 14, 2014
    Posts:
    39
    Thanks a lot, TonyLi!

    I finally got the randomized nodes working. Setting a variable on the Start Node with a math.random then onto three child nodes, checks the variable on which node will go to. Now I have NPCs starting up different conversation topics when initiated. Now I have to figure out how to have random 3 'answers' to choose from 6 predefined 'answers'.
     
  50. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Great! "3 from 6" is a classic random sample problem. A simple solution is to shuffle the list of 6 elements and then pick the first 3. Here's a shuffled() function in Lua:

    Code (Lua):
    1. function shuffled(tab)
    2.     local n, order, res = #tab, {}, {}
    3.     for i=1,n do order[i] = { rnd = math.random(), idx = i } end
    4.     table.sort(order, function(a,b) return a.rnd < b.rnd end)
    5.     for i=1,n do res[i] = tab[order[i].idx] end
    6.     return res
    7. end
    You can add this function to your dialogue database's Global User Script, which is on the Database tab:


    As handy as Lua is, I often prefer to write code in C#. Lua.RegisterFunction() makes it easy to use C# methods in Lua.