C# bool to lua?
C# bool to lua?
I'm not very experienced in coding. Need some help.
I have player, player have script and bool in it.
And now I want - when this bool is true or false converstation with npc starts with different sentence.
This whole lua thing is very confusing for me and I don't understand how can I do that - sorry if that is a basic question.
I have player, player have script and bool in it.
And now I want - when this bool is true or false converstation with npc starts with different sentence.
This whole lua thing is very confusing for me and I don't understand how can I do that - sorry if that is a basic question.
Re: C# bool to lua?
Hi,
Write a C# method that returns the value of your bool. Example:
This video tutorial shows how to make your method (GetMyBoolValue) available to Lua:
Then use it in the Conditions fields of your dialogue entry nodes:
Node 1:
Write a C# method that returns the value of your bool. Example:
Code: Select all
public bool MyBool;
public bool GetMyBoolValue()
{
return MyBool;
}
Then use it in the Conditions fields of your dialogue entry nodes:
Node 1:
- Dialogue Text: "MyBool is false."
- Conditions: GetMyBoolValue() == false
- Dialogue Text: "MyBool is true."
- Conditions: GetMyBoolValue() == true
Re: C# bool to lua?
Sorry for long break... I had to deal with different problems and now I comeback to this one.
So... I guess that I'm to stupid. I understand how to do it on dialog tab side but I have no idea how I suppose to register this. I already registered string and int (its in tutorial so I just follow it) but now I really need bool and have no idea how to do it:
Its obviously not working... How it should look?
So... I guess that I'm to stupid. I understand how to do it on dialog tab side but I have no idea how I suppose to register this. I already registered string and int (its in tutorial so I just follow it) but now I really need bool and have no idea how to do it:
Code: Select all
public bool isFollowing;
public bool GetIsFollowing()
{
return isFollowing;
}
private void OnEnable()
{
Lua.RegisterFunction("GetIsFollowing", this, SymbolExtensions.GetMethodInfo(() => GetIsFollowing()));
}
private void OnDisable()
{
Lua.UnregisterFunction("GetIsFollowing");
}
Re: C# bool to lua?
Hi,
What's not working?
Can you try using the starter template script? It's Assets / Plugins / Pixel Crushers / Dialogue System / Templates / Scripts / TemplateCustomLua.cs
What's not working?
Can you try using the starter template script? It's Assets / Plugins / Pixel Crushers / Dialogue System / Templates / Scripts / TemplateCustomLua.cs
Re: C# bool to lua?
I got this error:
Dialogue System: Lua code 'return GetIsFollowing() == false' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
Dialogue System: Lua code 'return GetIsFollowing() == false' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
Re: C# bool to lua?
That means the function isn't registered. Two possible reasons the function may not be registered:
1. The script isn't on an active GameObject in the scene.
2. Or you put it on a Don't Destroy On Load GameObject such as the Dialogue Manager but didn't add the extra "didIRegister" check that's in CustomLuaTemplate.cs.
1. The script isn't on an active GameObject in the scene.
2. Or you put it on a Don't Destroy On Load GameObject such as the Dialogue Manager but didn't add the extra "didIRegister" check that's in CustomLuaTemplate.cs.
Re: C# bool to lua?
I put it on NPC script. All of them is active, all of them have the same dialog triggers and the same conversation. They are not Don't Destroy On Load.
Actually I think about it now and I guess that is the problem... previously I was registering and checking on player. Now I want to have bool check on every NPC and it should be independent.
Conversation should check if this specific NPC isFollowing and on that condition show different dialog text.
How I should do it?
Actually I think about it now and I guess that is the problem... previously I was registering and checking on player. Now I want to have bool check on every NPC and it should be independent.
Conversation should check if this specific NPC isFollowing and on that condition show different dialog text.
How I should do it?
Re: C# bool to lua?
Hi,
When you register a method with Lua, it's globally accessible. You can't register GetIsFollowing() on an NPC named Ann and then try to register the same function name on an NPC named Bob.
Here are two possible solutions:
1. Include the NPC's name in the Lua function name:
If you put the script on a GameObject named "Ann", it will add a function named IsAnnFollowing().
If you put the script on a GameObject named "Bob", it will add a function named IsBobFollowing().
---
2. Or write a single method that accepts a GameObject name:
When you register a method with Lua, it's globally accessible. You can't register GetIsFollowing() on an NPC named Ann and then try to register the same function name on an NPC named Bob.
Here are two possible solutions:
1. Include the NPC's name in the Lua function name:
Code: Select all
Lua.RegisterFunction($"Is{name}Following", this, SymbolExtensions.GetMethodInfo(() => GetIsFollowing()));
If you put the script on a GameObject named "Bob", it will add a function named IsBobFollowing().
---
2. Or write a single method that accepts a GameObject name:
Code: Select all
public bool GetIsFollowing(string gameObjectName)
{
return GameObject.Find(gameObjectName).GetComponent<YourScript>().isFollowing;
// (Note: You should check if GameObject.Find and GetComponent return null.)
}
Lua.RegisterFunction($"IsFollowing", this, SymbolExtensions.GetMethodInfo(() => GetIsFollowing(string.Empty)));
Re: C# bool to lua?
Ok, I think I finally starting to understand it. I make it like that:
and I registered it on player.
Looks like it working.
Thanks.
Code: Select all
public bool GetIsFollowing()
{
return DialogueManager.currentConversant.gameObject.GetComponent<Knight>().isFollowing;
}
Looks like it working.
Thanks.