How to add/subtract int in C#

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

How to add/subtract int in C#

Post 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?
Last edited by Dumppermen10 on Mon May 06, 2024 8:08 am, edited 2 times in total.
User avatar
Tony Li
Posts: 20771
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add/subtract int in C#

Post 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);
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: How to add/subtract int in C#

Post 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)'
User avatar
Tony Li
Posts: 20771
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add/subtract int in C#

Post by Tony Li »

Sorry, I had a typo. It was missing "Coin". I just fixed my previous reply.
Dumppermen10
Posts: 9
Joined: Thu Mar 21, 2024 5:07 pm

Re: How to add/subtract int in C#

Post by Dumppermen10 »

Ahh. It worked like a charm.
Your Brilliant Tony! Thankyou very MUCH. :mrgreen:
User avatar
Tony Li
Posts: 20771
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add/subtract int in C#

Post by Tony Li »

Glad to help!
Post Reply