Keep score with Blueprints

I am trying to make a score like Swing ninja, where you pick up an actor and it adds to your score, but I couldn’t make sense of the example in Swing Ninja. I got the pickup done, but I want it to update every time the player overlaps the pickup. In code you could just say Score = Score + Whatever, but no idea how to do that in Blueprint.

Here’s what I tried.

Your setup is correct, that is indeed how to add and set int.

2423-untitled.jpg

Is it even printing the new value? Maybe that event isn’t being called. Put a breakpoint on a node (e.g. click Spawn Emitter at Location and press F9), then play your game and see if it’s halting there.

You just need a Get and a Set, with some math. Here’s a really quick proof-of-concept for adding to the existing value:

I set this to Auto-Receive inputs (it’s in the BP’s Defaults if you wanna try) and then drop it in the level. As I spam the G-Key, I get a constant upward count. 1… 2… 3… etc.

Hope this helps!

Dawww! So close!! :smiley:

No, it just prints 1 over and over. Is it because each pickup is individual, and so each is running the same code without adding to some global variable, say in the level or on my character blue print?

Top left is what I get.

Wait. Where are you storing the score?

Thank you, that setup works by itself, but not when I apply it in the pickup BP. I’m thinking I may have to put it in a different class.

Within the pickup. Now that I think about it, probably not the best place.

No, you’d want that to be within the player or within some other class that overarched your game. You probably COULD do it in the pickup, but then all pickups would have to be talking to one another all the time, which would be unnecessarily heavy.

Ok, that’s sounds good, do I need to use an interface to do that? (Sorry, new to this)

Most is right now. :smiley:

You shouldn’t really need an interface. Blueprints are built to be able to communicate with each other directly. You just need to know how to call them. One possible approach would be:

I made a new Class Blueprint called ScoreHolder. It has a Score variable (int), and a function named Increment Score. The graph for that function looks something like this:

From your pickup class, use a Begin Play event to trigger a Get All Actors of Class, set to look for your ScoreHolder class. This will store them in an array. Get the first (0) element of that array and cast it to a ScoreHolder class. This is required because that node doesn’t know what’s in there by itself. Take the output of that and store it into a new variable with a type of ScoreHolder.

Still with me? :smiley:

Then you can just use that variable to call your Increment Score function whenever you like. The graph for my (not quite a) pickup class looks like this:

When I do this I get a steady count of 1…2…3…etc.

Hope this helps!

Also, note that you don’t have to make a separate class just to hold your score. You can put that in your GameMode (that’s probably where I’d put it), or on your character, or whatever you like.

Worked Beautifully! Thank you for this, and all the videos for UDK as well. :slight_smile:

http://youtu.be/28dfsstb59Q

I recorded a video that extends a little on Zak’s explanation. I was trying to figure this out for days :slight_smile:
Happy to get there. Hope it’s helpful.

Tom

Yes counterpart0, it just prints 1 over and over.How can i fix it?

Hey Luka, as counterpart0 discovers earlier in this post, his problem was that he was doing all the math in the pickup class itself. That’s a problem since each pickup is basically only keeping its own score when it gets picked up. What you need is for some other Blueprint (the character, the game, a separate actor) to keep track of when things get picked up, and increment the score from outside the pickup.

All of this is covered in the posts above. I even put in some pretty pictures! I hope they help! :slight_smile:

EDIT: This answer brought to you by who is having AnswerHub difficulties at this time.

That isn’t enough information to reply exactly.

what variable type is the score holder ?

You can create the variable when you click Asscore holder C (blue pin), then choose “Promote to variable”, it automatically creates the Score holder variable then.

Worked perfectly, thanks :D. had this problem for so many days. I put the score holder in a billboard class and placed it in the level.