Hi,
tuncturel wrote:Problem 1:
I have a text that reads: "You seem to have X gold coins with you. Did you talk to your associates A, B, C and D about getting a loan?"
Now what I want to do is fill in X, A, B, C and D with respective variables from my Scriptable Object Database. I don't want to use any of the Quest, Item, Location etc. stuff that comes with the system because they don't seem like what I need and I can't seem to find a comfortable way of editing them through code(Maybe I'm missing info on this? help!). My database is of a certain shape and is accessible by code since it's a singleton but I don't know how to access it via the Lua commands.
I just need a method that says: UpdatePartOfText(string remove, string replace).
Here are three ideas:
1. Consider using Dialogue System variables after all. It makes the dialogue writing much easier: "You seem to have [var=gold] gold coins with you. Did you talk to your associates [var=npcA], [var=npcB], [var=npcC] and [var=npcD] about getting a loan?"
Use
DialogueLua.SetVariable() to set Dialogue System variables in your code:
Code: Select all
using PixelCrushers.DialogueSystem;
...
DialogueLua.SetVariable("gold", MyScriptableObjectSingleton.GetNumGold()); //(example)
You can use an OnConversationStart method to set the Dialogue System variables based on the current values in your database.
2. Or, register your C# code with Lua, and use the [lua] markup tag: "You seem to have [lua(GetInt("gold"))] gold coins with you. Did you talk to your associates [lua(GetString("A"))], [lua(GetString("B"))], [lua(GetString("C"))] and [lua(GetString("D"))] about getting a loan?"
Add something like this to your singleton script:
Code: Select all
using PixelCrushers.DialogueSystem;
...
public class MySingletonClass : MonoBehaviour {
void Start() {
// If your singleton is a MonoBehaviour, you can register your code here.
// Otherwise you can add a constructor method.
Lua.RegisterFunction("GetInt", this, typeof(MySingletonClass).GetMethod("GetInt"));
Lua.RegisterFunction("GetString", this, typeof(MySingletonClass).GetMethod("GetString"));
Lua.RegisterFunction("GetBool", this, typeof(MySingletonClass).GetMethod("GetBool"));
}
}
This is a totally made-up example since I don't know your singleton code. I just guessed that there might be functions called GetInt(), GetString(), and GetBool().
3. Or, taking a completely different approach, add a script to the Dialogue Manager that has an
OnConversationLine method. The Dialogue System calls this method before showing a subtitle. It gives you a chance to modify the text first. For example, say you decide to use angle brackets to specify code to substitute: "You seem to have <X> gold coins with you. Did you talk to your associates <A>, <B>, <C> and <D> about getting a loan?"
Then make the OnConversationLine(
Subtitle) method look something like this:
Code: Select all
void OnConversationLine(Subtitle subtitle) {
subtitle.formattedText.text = FillInVariables(subtitle.formattedText.text);
}
string FillInVariables(string s) {
// Put your code here to process the string and return the result.
}
tuncturel wrote:Problem 2:
I want to present replies depending on my database as well. For example let's say after asking "You seem to have X gold coins with you. Did you talk to your associates A, B, C and D about getting a loan?" I want to put possible answers as the following:
- I talked to A.
- I talked to B.
- I talked to C.
- I talked to D.
So if there was a 5th guy in my database I would add -I talked to E as another option.
Could someone kindly guide me in the right direction?
It's easiest if you can add E when you're writing the conversation, and then at runtime make it visible or not based on a condition. In this reply, I'll assume you can do that. (If you need to be able to add new responses at runtime, let me know. Otherwise I'll spare you the wall of text.)
You could once again define variables in the Dialogue Editor such as "talkedToA", "talkedToB", etc. Then set each dialogue entry node like this:
- Menu Text: I talked to A.
- Conditions: Variable["talkedToA"] == true
(You can use the Lua wizard; you don't need to type this manually.)
In the conversation with A, you can set the first dialogue entry node (or whichever node is appropriate) like this:
- Dialogue Text: Hi, I'm A!
- Script: Variable["talkedToA"] = true
If you don't want to do that, you could again register your code with Lua and then call that in the Conditions and Script fields:
- Menu Text: I talked to A.
- Conditions: GetBool("TalkedToA") == true
(You can't use the Lua wizard in this case because it doesn't know about your custom-registered functions.)
and:
- Dialogue Text: Hi, I'm A!
- Script: SetBool("TalkedToA", true)
I'm sure there are other good ways to approach this, too. So if these don't work for you, let me know.