playMaker

Author Topic: Novel ways to store data.  (Read 2332 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Novel ways to store data.
« on: August 09, 2013, 04:03:47 PM »
Okay, so, i'm a fan of keeping things as tight as possible and as clean as I can and this usually means that i'm trying to condense as much information as i can into a small a space as I am able.

So, thought i'd share some of my approaches. some of these take some time to set up but they can result in lower overhead in some cases.

Three ways to store data in ways you might not have thought of.

Vector3 variables: If you're working with numeric data, even integers, a vector3 variable is one way you can store three points of data with one variable. sure, they're made to work with floats so if you want to store integer values in them you have to convert them but this is something that i've been doing... it also adds a small level of obfuscation because most people that'd hack a game (to implement cheats and such since this wouldn't do anything to stymie piracy that i'm aware of) wouldn't think to check the vector3 variables for game data that isn't positionally or orientationally minded.

So, example: Vector3== X:player class id code. Y:total experience points Z:maybe health or speed or some other value you need to transfer around.

Note, this is not very practical for stuff that you have to run while the game is running... it's better for things like set-up and save/load states with the player prefs. it's not really practical because you have to grab each of the values and separate them which is an extra step that you might not have CPU resources for.

Using an int as a binary inventory.

If you are like me and the other half of the 10 types of people in the world that can parse binary (see what i did there? har har har!) you'd know that binary can represent a simple integer value that can give you a whole selection of on and off states... so, this could be used for things like storing a key-items inventory or key/access-card system...

example: Say you have three keys... red, blue and yellow.

Red can be 1, blue can be 2 and yellow can be 3....

if you have all three, the binary could be 111
if you only have the red and the yellow the binary could be 101.

If you translate these to their integer value, all three would be an int of 7, the red and yellow would be an int of 5.

it's actually easy to break it all down too... consider powers of two.

imagine you have a sheet with columns along the top with the values of

1|2|4|8|16|32|64|128... etc.

this does rely on being able to udnerstand binary and i'm not a math teacher (well, i'm not good at teaching math since it's not one of my strong suits but this is something i had to learn when i was trying to learn to make sweet games on my commodore64 back in the day... i only ever really got good with basic though so that's why i went with Playmaker.)

stashing the data should be easy... when you want to record that the player has picked up an item, you simply add to the integer variable the value that is on this one's column... so, fourth column? add 8. an interesting thing with all this, this is also how old-school programs would encode sprites which were simply pixels with an off or on state (and the layer had it's own colour.)

Thing is, extracting the right information is tough though because you essentially have to set up a system to test for each permutation... unless there were some actions set up to work with binary values (hint hint, Jean... maybe consider some binary actions to your data-maker plug-in?) so, to extract you have to have a test for each permutation and a listener with a switch that has up to 128 different numbers can get out of hand real fast... I usually use this for small values so that I Can keep the extraction simpler. I am using this in my game currently with the weapons collected... since there are 6 and the player will always start with the first two, i only have to set up a switch for 8 integer channels...)

And one more...

What is a colour variable?

Why, it's simply four float values in an array... red, green, blue and alpha. what testing i've done with this does mean that you are limited in positive integer values that will never be more than 256 each... but if you are okay with that kind of limitation, you can easily use a colour variable to store this.

I was working on integrating this into the navigation system i was working on before navmesh became indie friendly... and it also allowed me to store up to four "distance" values for four players... so, player one had red, player two had gree, player three had blue and player four had alpha... and since the distance value would never be more than 25 (arbitrary number though...) I could then pass this single variable to the enemies that would be needing to calculate where the player was (so, it'd find the closest node, it'd extract it's colour* and from there determine which player is how far away... sure, i had this one where it would only chase a player it had already encountered but if it was alerted, it would find the closest node, the value of distance and figure out which node nearest to this one had a value that was lower and go to that one... repeat until player one is visible again.)

*The node itself is invisible so the colour that shows is unimportant

What other interesting ways have you found to stash data in your game?