How do I make a button add a value to a counter?

I have a game where you are given options In a widget by clicking on buttons that take you to the next scenario. How can I make it so every button has a coded value and it adds them all up at then end. For example level 2 option 1 has a value of 30$ and option 2 has a value of 10$ After the player completed the level I want that value to be added to the total so on final screen it will read how well the player did playing the game. I have been trying for a few weeks to figure it out. Any suggestions?? Or Help?

Bump…

Bump…

Hi

You need to create your own GameInsatnce and there you need to create the counter

To configure your GameInstance you should go in settings → maps and mode ( there are lots of information on internet )

To access the gameInstance you can simply call GetGameInstance node an cast to YourGameInstance

GameInstances are used to save data between levels. Any other ‘files’ are reseted after loading another level

So I guess this was your problem: when you load another level, the counter was reseted to 0. Am I right ?

How would i configure the counter within the Game Instance

First, create a blueprint of GameInstance type

Okay after that how would i call the game instance and then make the button add changes to the game instance

Now how do I edit that and make my on clicked event change the game instance I have that game instance and everything now. I want to be able to click on option 2 and have it change the value how do I do that? Thank you for your help

Now how do I edit that and make my on clicked event change the game instance I have that game instance and everything now. I want to be able to click on option 2 and have it change the value how do I do that? Thank you for your help

Hey there,

First, create your own Game Instance Class. The Game Instance Class is used to store Data between Level-Changes.

http://puu.sh/omhm1/6c319159fc.png

Open your newly created Game Instance Blueprint and add a new Integer Variable called Counter.

http://puu.sh/omhs4/5ae0e72de5.png

Then, right-click into the Event Graph of your Game Instance Blueprint and search for Custom Event.
Select that and name the new Event IncreaseCounter. In the options of this Event (select it to see them on the right side), add an Input of Type Integer and name it InValue. Then do the following:

http://puu.sh/omhDJ/6f4a877aa2.png

You can use this Event in your Widget to increase the Counter Variable that is placed in your Game Instance class.

Now you need to set this Game Instance Class is the default one that the Game should use.

Open your Project Settings by clicking on “Edit → Project Settings” in the Main Editor Window.

http://puu.sh/omhIZ/417db3d91f.png

Click on Maps and Nodes and select your Game Instance Class in the bottom most Drop-Down Menu:

http://puu.sh/omhLs/7da73e434f.png

http://puu.sh/omhO1/7055f976c8.png

Now, in your Widget (or where ever you want), you can call Get GameInstance, cast it to your custom Game Instance Class and call Increase Counter.

http://puu.sh/omhUp/27c0171121.jpg

That should do the trick. If you still need help, i HIGHLY recommend to watch/read some more tutorials (:

Cheers!

THANKS SO MUCH but one last question if you can. Now at the end of the game how would I display the score. Would I just call game instance to view port and make a widget that contains that?

Yes, when ever your game ends ( that’s up to you to figure out (: ), you create a Widget that has some text or what ever you want to display, but also a Text Widget for your Score.

Then you can, again, call GetGameIntance, Cast it to your custom GameInstance Class and get the Counter Variable directly (: No event needed for this.

That’s all (: Also, please make sure to accept an answer if it solved your question!