Hey Tony.
I had another question. How do you Add/Subtract a int variable in C# script? Been digging through this website and I can't find no simple solution for it anywhere.
Example.
public int Coin = 100;
void Start()
int Coin = DialogueLua.GetVariable("Coin").AsInt;
DialogueLua.SetVariable("Coin", 150);
public void Punch()
Coin + 10;
----------------------------------------------------------------------------------------------------------
Now Coin = 160. After void Punch() is activated.
This is what I want. but it don't work?
How to add/subtract int in C#
-
- Posts: 9
- Joined: Thu Mar 21, 2024 5:07 pm
How to add/subtract int in C#
Last edited by Dumppermen10 on Mon May 06, 2024 8:08 am, edited 2 times in total.
Re: How to add/subtract int in C#
Hi,
If you want to add or subtract a C# variable from within a conversation (e.g., a dialogue entry's Script field), please see How To: Connect C# Variables to Dialogue System's Lua.
If you want to add or subtract a Dialogue System Lua variable variable from within C#, use DialogueLua.GetVariable() and SetVariable().
In your Punch() method:
If you want to add or subtract a C# variable from within a conversation (e.g., a dialogue entry's Script field), please see How To: Connect C# Variables to Dialogue System's Lua.
If you want to add or subtract a Dialogue System Lua variable variable from within C#, use DialogueLua.GetVariable() and SetVariable().
In your Punch() method:
Code: Select all
DialogueLua.SetVariable("Coin", DialogueLua.GetVariable("Coin").asInt + 10);
-
- Posts: 9
- Joined: Thu Mar 21, 2024 5:07 pm
Re: How to add/subtract int in C#
Thanks for the quick reply.
Ok just did it but I got an error?
error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'DialogueLua.SetVariable(string, object)'
Ok just did it but I got an error?
error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'DialogueLua.SetVariable(string, object)'
Re: How to add/subtract int in C#
Sorry, I had a typo. It was missing "Coin". I just fixed my previous reply.
-
- Posts: 9
- Joined: Thu Mar 21, 2024 5:07 pm
Re: How to add/subtract int in C#
Ahh. It worked like a charm.
Your Brilliant Tony! Thankyou very MUCH.
Your Brilliant Tony! Thankyou very MUCH.
Re: How to add/subtract int in C#
Glad to help!