Page 1 of 1

How to add/subtract int in C#

Posted: Mon May 06, 2024 7:57 am
by Dumppermen10
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?

Re: How to add/subtract int in C#

Posted: Mon May 06, 2024 8:06 am
by Tony Li
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:

Code: Select all

DialogueLua.SetVariable("Coin", DialogueLua.GetVariable("Coin").asInt + 10);

Re: How to add/subtract int in C#

Posted: Mon May 06, 2024 8:14 am
by Dumppermen10
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)'

Re: How to add/subtract int in C#

Posted: Mon May 06, 2024 8:22 am
by Tony Li
Sorry, I had a typo. It was missing "Coin". I just fixed my previous reply.

Re: How to add/subtract int in C#

Posted: Mon May 06, 2024 8:29 am
by Dumppermen10
Ahh. It worked like a charm.
Your Brilliant Tony! Thankyou very MUCH. :mrgreen:

Re: How to add/subtract int in C#

Posted: Mon May 06, 2024 8:58 am
by Tony Li
Glad to help!