Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Tutorials
#1

Creating The Ultimate Scoreboard

Archive: 6 posts


Note- When using binary I work from right to left just like I would going from ones to tens to hundreds in decimal. I also work from bottom to top. Feel free to go whichever way feels right for you, but the components described in this tutorial may need to be modified accordingly.

Creating the ultimate scoreboard is actually fairly easy once you know what you are doing and have a good toolkit at your disposal. This tutorial is going to be pretty long, so bear with me. I will do my best to make this as easy as possible to follow.

First thing to consider is how to store the score. Some folks prefer an analog method with timers and the like, but they are just too imprecise to me, and overflow can be a nightmare unless you restrict yourself to certain input ranges. I know what you are thinking, “But I don’t want to learn binary”. Don’t worry, you don’t have to. You just need to know a few basic concepts that I will cover in the next few minutes.


Think of our traditional decimal numbers. Now we count up to 9 and then roll over to the next place by adding a 1 to the left and starting over. Now imagine that instead of 0-9 we are using a counter set to count to 10 with its output on its own reset, and on the input of a counter to its left.

That would pretty accurately represent basically how we count. Binary is no different except now our counters only go to 2. All the same addition and subtraction rules apply.

In circuits we represent each number as a bit. Each bit has a value of either 1 or 0 just like our counters.

so in counting we would go:
1 = 001
2 = 010
3 = 011
4 = 100
and on and on.

That, in a nutshell, is how binary works.


What we need is a register to store the score. Basically this is just a series of bits. In order to build our register we need to first know what our maximum score will be. For this, I am just going to 15, but yours could be anything. I use this conversion tool (http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html) to determine how many bits are needed, and to double check values as I go. Just enter the number, hit convert to binary, and count the number of digits are in the result. Since I am only going to 15, I need 4 bits.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/Toggles.jpg

Well there we go. We now have 4 bits, but that’s not very useful for storing a score. We need a way to add to the values; not just flip them on and off. In order to do this we will need some form of adder circuit. We could use a half adder, but that won’t allow us to take into account values carried over from the previous bit. What we need is a full adder (http://www.play-hookey.com/digital/adder.html).

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/Fulladderlabeled.jpg

This is great. We can add and combine values together, but we still need a way to store them. Fortunately LBP2 provides an interesting way to do this. If we loop the output of an OR gate back onto one of the inputs, it can become a storage.

Knowing that, we can now suppose that XOR gates would behave similarly since they are, at the core, modified OR gates. So, if we take our S output from our full adder and loop it back into the A input, we have what we need. We have a bit that can act as a storage, and perform addition operations on it.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/Modifiedadder.jpg

If we attach some tag sensors to the B inputs of the modified adders, and run the Cout of one bit into the Cin of the next, we have a working score storage device. Just label the tag sensor according to the bit it corresponds to. In my case 1, 2, 4, and 8. Sending a pulse to any combination of these tag sensors will add that value to the score storage.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/register.jpg

If everyone could read binary we would be done right now. You can store the score, add any number to it, and display it. Unfortunately everyone can’t, so we need a way to display things that makes it easy to read.

This is where something called a BCD (Binary Coded Decimal) comes into play. It is just what the name implies. It takes a four bit binary number and converts it to a decimal value. They’re fairly easy to make, so let’s make one.

First you need to make the numbers 0-9. Sticker panel makes a great material for this, but you have to switch to preview mode to see which number is active. So, you may want to use holo to make the numbers for now. That will make testing easier. Then switch them over to sticker panel with the material changer once everything is ready to go.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/Numbers.jpg

Now that we have the numbers, we create a microchip to translate four bits of binary into a decimal number. While this sounds pretty complex, it’s really just 10 AND gates with four inputs each. You will also need four NOT gates.

Run each of your inputs into its own NOT gate. Now, run either the input or the NOT gate into each of the ANDs depending on if the bit should be on or off. for example:


0= 4NOT 3NOT 2NOT 1NOT
1= 4NOT 3NOT 2NOT 1ON
2= 4NOT 3NOT 2ON 1NOT

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/BCD.jpg

Once this circuit is built and all of the outputs are run out to their corresponding number, layer all of the numbers together and glue them. then place that chip on it.

Yay, we’re done!!! Ok, not really. if we were only going to 9 we would be, but we are not. we are going all the way to 15. Our BCDs only go to 9. We need another digit. This means we need a way to convert the binary into something that we can input into a BCD. It would be nice if we had something that could do that for us. Fortunately we do.

Enter the double dabble (http://en.wikipedia.org/wiki/Double_dabble). Essentially, what this does is shifts all the bits left one, checks if they value is greater than 4 then adds three if it is. This is what a 16 bit double dabble looks like in LBP2.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/16bitdoubledabble.jpg

Each of those chips are three adders. They use comparisons to check if a value is five or higher, and if it is they add three. Since we only have 4 bits we only need the most basic double dabble....one three adder chip.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/4bitDD.jpg

and what's inside it.
http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/ThreeAdder.jpg


For our purposes here, that works fine and we could call it a day, but what if we want to have a score higher than 15? Then we need to stack these chips in sets of three. At each level, you can have fewer than three, but never more.

Here’s a quick lesson on stacking them together. As we’ve discovered, for 4 bits you only need one of them.

The lowest order bit goes straight through to the BCD, the next goes into the first input and then the rest follow suit. There should always be one open input on your highest order three adder in each set.

Now, if we want to make our binary input larger by adding two bits, for each new bit we would have to stack on another three adder, otherwise we would not have an open input. We would do the same thing for the next bit as well.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/6BitDD.jpg

Now, this is where it gets tricky. Since we have reached our limit of three for this set, if we want to add another bit, we have to start a new set. This set will be comprised of two adders in each level. A 7 bit double dabble would look like this

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/7bitDD.jpg

This works for up to 9 bits before we need to start a new set with three chips.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/9bitDD.jpg

We just continue chaining them by adding one more to the set every three bits until we reach the number we want. Notice I have kept the output nodes grouped in fours. This is because each of those groups are individual BCD input values. Doing this will make it easier to attach to your BCDs later.

Just keep these rules in mind and you should be fine..


The first bit always passes straight through to the BCD
For the first four bits in a register you need a single adder. For every bit after that, you need a new one.
The adders work in threes. For 4-6 bits you only need a single stack of adders. For 7-9 you will need that stack, plus another double stack.
The highest order input on each stack should always be open.


Now just connect your outputs from the double dabble into your BCDs and you are done.

http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/Finished.jpg

Thanks for reading! If I've missed anything, or if something could use more explaining, feel free to post a reply. I'll do my best to answer.

I think we have done enough for now. We’ve actually built a very good basic scoreboard. I may come back later and cover how to handle multiple simultaneous scoring as well as using subtraction to make this a fully functional bank for RTS and Tower Defense levels. I will also cover how to limit the binary values so they don’t roll over.

If anyone is interested in helping make a level to go along with this, please PM me. I'm pretty rubbish at tutorial levels.

In the meantime if anyone would like to see an example of this scoreboard in action, you can check the level in my sig. It uses this exact method, but has some buffering going on so I could store two values in order to roll the scores back.

sorry about that downtime. One missed quotation mark ended up causing an entire section to be omitted. Everything should be back together now.
2011-10-19 23:37:00

Author:
tdarb
Posts: 689


Slow down please! Ok. I have my 4 switches on a chip... Now what? D:

In all seriousness though, my head was about to explode when I finished reading through the entire post lol. I knew it was possible to come up with this kind of thing (this level of complexity) but never actually saw anyone explaining any of it.
I doubt I'll be using this in my lifetime, but a huge kudos not only for making it, but taking the time to explain everything bit by bit (no pun intended).
2011-10-20 11:34:00

Author:
MonarioBabii
Posts: 128


thanks

lol, yeah. It's a lot to take in. It's really less complicated than it seems once you dive into create and start making the scoreboard. If there's something that is unclear, let me know so I can fix it. I want to make this as easy as possible to follow, because while this is just a basic scoreboard, it is also the starting point for some really cool stuff.
2011-10-20 13:48:00

Author:
tdarb
Posts: 689


Some folks prefer an analog method with timers and the like, but they are just too imprecise to me...

As long as you stick with values which are precisely representable in IEEE 754 (http://en.wikipedia.org/wiki/IEEE_754-2008), you'll get about 224 discrete values per wire with no loss of precision, although converting it to show on a custom display is a complete pain in the butt.



...and buffering can be a laggy nightmare.

How so? If you use an analog D-latch, it should be zero-latency.

Still, for this particular example, the analog to digital conversion required to create a display for an analog buffer is probably just as expensive as using an all-digital solution.



What we need is a register to store the score.

I like the efficiency of using a fedback adder, rather than bothering with an external selector-based buffer, although the selector-based buffer has one advantage which is that it'll remember the score even if it's inside a disabled microchip.



First you need to make the numbers 0-9. Sticker panel makes a great material for this, but you have to switch to preview mode to see which number is active.

Seems to work okay with Sticker Panel if you set Opacity when off to 0%



http://i135.photobucket.com/albums/q149/tbradt/lbp/Scoreboard/ThreeAdder.jpg

Nice. Less thermo than my previous design.
2011-10-22 01:16:00

Author:
Aya042
Posts: 2870


When I mentioned that analog is not as accurate as i like, i was thinking more of the fact that you are limited to 33.3% in a single shot. You have to know which timer settings don't have rounding errors, and even then you have to work out the conversions. With a binary system, it is always accurate and very easy to plug in any value at any time without conversions that are dependent upon how the timer duration impacts the percentage per frame.

as far as the buffering, I was thinking of overflow. Thanks for pointing that out. I've changed the OP.

Sticker panels work beautifully, but when in create mode, and not in preview, placing 10 digits on a single layer is impossible to read. Even with the opacity settings at 0%, it is still completely opaque in create mode. This leaves 9 digits having a black silhouette. It just works better to use holo while testing and switch over after. Since you can still use the R2/hide feature with the material changer, it's very easy just to change, hide, change, hide.

I didn't design the chip you showed. I wish i could take credit, but Tygers made that one. It's much better than what i was doing. Mine worked, but had around 30 more components. I was actually using full adders to add 3 lol.

You mentioned something when we were talking earlier that made sense. There's really not much of anything that this does that can't be done using the in game score. I just like to make minigames and app style levels. In those cases, I like having control over the display without having the score constantly popping up on the left. In terms of pure functionality this is largely redundant, but it is useful in levels where the way in which the score is displayed is important to the feel of the level.
2011-10-23 07:36:00

Author:
tdarb
Posts: 689


When I mentioned that analog is not as accurate as i like, i was thinking more of the fact that you are limited to 33.3% in a single shot.

Only if you're using timers to store values, but no-one does that any more.



You have to know which timer settings don't have rounding errors...

...or just read this (http://wiki.lbpcentral.com/Talk:Timer).



Even with the opacity settings at 0%, it is still completely opaque in create mode.

That's a shame. Oh well, I guess there's always seven-seg.

Another option I looked at when I needed an 8-digit readout with 32 possible chars per 'digit' was emitters, so that you only pay for (in theory) 8 pieces of holo/whatever rather than 256.



I didn't design the chip you showed. I wish i could take credit, but Tygers made that one.

Huh. Just noticed he posted it in this thread (https://lbpcentral.lbp-hub.com/index.php?t=48803-8-bit-Digital-Readout). Must've missed it the first time around.
2011-10-23 18:06:00

Author:
Aya042
Posts: 2870


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.