x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.10
Tags:
more ▼

asked Mar 23 '16 at 04:15 PM in Using UE4

avatar image

JakesLegacy
1 1 3 2

avatar image JakesLegacy Mar 24 '16 at 12:57 AM

Bump........

avatar image JakesLegacy Apr 17 '16 at 05:41 PM

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

avatar image JakesLegacy Mar 25 '16 at 01:38 AM

Bump..........

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

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 ?

more ▼

answered Mar 25 '16 at 01:30 PM

avatar image

Unicornslayer
51 1 2 4

avatar image JakesLegacy Apr 17 '16 at 05:42 PM

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

(comments are locked)
10|2000 characters needed characters left

How would i configure the counter within the Game Instance

more ▼

answered Mar 25 '16 at 05:19 PM

avatar image

JakesLegacy
1 1 3 2

avatar image Unicornslayer Mar 25 '16 at 08:16 PM

First, create a blueprint of GameInstance type

alt text

alt text

1.png (76.4 kB)
3.png (79.8 kB)
avatar image JakesLegacy Apr 01 '16 at 03:30 PM

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

(comments are locked)
10|2000 characters needed characters left

Hey there,

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

GameInstanceCreation

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

CounterVariable

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:

IncreaseCounterEvent

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.

OpenProjectSettings

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

MapsAndNodes SetGameInstanceClass

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.

WidgetButtonPress

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

Cheers!

more ▼

answered Apr 18 '16 at 01:10 AM

avatar image

eXi
6.6k 329 181 462

avatar image JakesLegacy Apr 18 '16 at 02:10 AM

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?

avatar image eXi Apr 18 '16 at 04:15 AM

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!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question