Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: jalex19 on March 27, 2012, 02:52:37 PM

Title: Simple Score System [SOLVED]
Post by: jalex19 on March 27, 2012, 02:52:37 PM
So warning this is a bit n00bish but I'm mainly looking for how to get started putting a basic score system together using playmaker.

What I'm looking for at a high level:

An integer display somewhere on the screen (let's say upper right) that reads in from a variable.

A way to increment this variable using various game objects (Say I can collect 3 types of boxes: Red, Blue and Green - I would like for these objects to fire off an action (probably global?) that increments the variable by a set amount.

Eventually I'd like to learn how to save these variables across levels etc but for now this would be a good start. I've tried searching the forums and tuts but I didn't see something that would directly apply, and if so it wasn't immediately obvious - sorry!

I appreciate any help!
Title: Re: Simple Score System
Post by: justifun on March 27, 2012, 04:39:30 PM
Here's a tutorial that might help with part of it


But yes, you can easily do all of what you want to with playmaker.

One way to handle this and to keep it flexible as your game expands, is to create a "manager" type of FSM.

Create an empty game object and attach a new FSM

This will handle all of the math and displaying of your scoring system and every other gameobject in your game will interface with it and update the scores as necessary.

While there are a lot of different ways to go about it, here's just one of the ways you could do it.

Were going to make sure of what are called global transitions for this setup and seperate each of the adding and subtracting states to keep things visually easier to understand.

Create a few new events for each of the things you want the manager to do and make them global
eg: Add points, Subtract Points

Make a new state for each of these events and add them as global transitions
(right click the state name and choose "add global transition" and pick the new global event you created)

Create one final state that after adding or subtracting your scores, this state will update the scoreboard for the player - you'll only want to do that each time the player gains or loses points instead of every frame for example)

still with me?

3 seperate states (add points, subtract points, update score display)
-add and subtract each have a global transition on them

Ok, on the add and subtract points states you'll want to add a "int add" action that will add or subtract a value from a global variable.  This variable can be setup at a pre determined value in the variable tab, or  you can have each different type of enemy change this amount depending on when it gets killed and how - more on that later

Lets say for now you make a global variable called "enemyPointReward"

the value amount of the int add action should be set to the enemyPointReward variable.

Now add a FINISHED event to each of the add/subtract states by right clicking the state and choosing add transition, then right click the new .... box and pick FINISHED.

Now connect up the FINISHED events to the 3rd state you created earlier called "update score display"

Next we need to create another new variable called "scoreString"

this will be used to convert the integer score into a string so it can be displayed in the GUI text object you'll create

Now in the update score display state you are going to add the following actions
Convert Int to String (to convert the score variable into a string)
Set GUI Text (to display the now string version of the score INT )

Make sure you set the "object" in the gui text action to your GUI text object that you are using to display the score in.
and for "text" use the scoreString" variable

The last part of the puzzle is to pick when your game is going to request a scoring update to the manager.
Depending on the design of your game, you could do it each time one of your enemies dies, or the player picks up a power up for example.  Either way, wherever you want to put it, you'll need to add a "send event to FSM" action, and pick the score manager FSM on your empty game object as the object in question, with the FSM name you added to it, and then for the event field put "add points, or subtract points, or whatever name you used for the global transitions)

Now you have the flexibility to use the manager anywhere in the game by any other object in the game to update your score however you want to.  You simply create new conditions in your score manager to do whatever you want all in one place, thus keeping all of our other FSMs on your game objects cleaner and seperate.

Boy would this have been easier with a screen shot, sorry but im not at my work machine right now.  I will try and follow up with one later.


cheers!
Title: Re: Simple Score System
Post by: Alex Chouls on March 27, 2012, 05:05:39 PM
EDIT: justifun posted a thorough response while I was writing this. Hopefully mine doesn't confuse the issue ;)

Some tips to get you started. As usual, there are lots of different ways to do this in Unity/PlayMaker, but this should help get you over the hump so you can play with different approaches yourself...

Setup the score Display:

Use a GUI Text to display the score.
Main Menu > GameObject > Create Other > GUI Text.
Place and size the GUI Text using the Inspector.
Consult the Unity docs if the controls are unfamiliar - they take a little getting used to, but are pretty powerful!

Now add an FSM to the GUI Text GameObject.

The screenshots should help you build the FSM:
1. Add actions to display the score (first attached screenshot).
2. Add a state to increment the score with an event (second screenshot).
3. Expose controls so you can run the game and test the FSM.

This example is built more for clarity than efficiency, and might not scale well in your case - it depends how many pickups you have... You can also look into Set Event Data and Get Event Info to make a more generic Pickup state.
Title: Re: Simple Score System
Post by: jalex19 on March 27, 2012, 08:12:48 PM
You guys are awesome! Taking some time to read through this and digest, I'm also checking out Xtopher's health pickup vid which seems to have some good info. Once I get the system working I'll update the thread.

It's been about a year since I've worked in Unity (finally got myself a daytime design gig). My last Unity project/prototype is here: http://www.openmicgames.com/games/tantrix (http://www.openmicgames.com/games/tantrix) which was quite complicated to script from scratch and I needed a bit of help. My experience with Playmaker thus far has blown my mind - I've done mod work in Unreal and Cryengine and in many ways this is even better than Kismet/Flowgraph. (You rock Alex!)

In my spare time I hope to make a shipable lightweight game for mobile, so I really appreciate the solid and active community!
Title: Re: Simple Score System
Post by: Destide on March 28, 2012, 10:48:02 AM
Just wanted to say thanks for posting guys all of you just solved a massive headache for me.
Title: Re: Simple Score System [Solved]
Post by: jalex19 on April 02, 2012, 11:01:18 PM
Got a simple score system in and working, the above methods all helped! Thanks!
Title: Re: Simple Score System [SOLVED]
Post by: nabilfx on May 17, 2015, 12:05:09 PM
I need to score a float number, into a sql  and php  online. Any help please?