playMaker

Author Topic: Need advice on data driven design  (Read 116 times)

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Need advice on data driven design
« on: November 03, 2017, 04:40:45 AM »
Hi guys,

A while ago i had a suggestion for the option to export/import global variables into a spreadsheet for easier editing. Jean and Djaydino were appaled by the number of global variables i use at the moment (more than 800). For me, it was the most logical way to store data since i could access it from anywhere in the project. I was a beginner and i felt that using local variables is too limiting, especially when time comes to tweak things like attack or health points of certain enemies for example. Downside to that approach (besides security and naming), as i noted further down the road, is the impossibility to manipulate it in a more meaningful way than variable by variable in a closed Playmaker environment. Besides that, local variables that don't draw data from a data source are easy to mess up and hard to debug sometimes.

In terms of programming, i'm currently in the phase of knowing more each day, but aware that i actually have more and more to learn. As a method of learning, i decompiled a lot of stuff made in Unity by opening .dll files with Resharper. I noticed that majority of games use JSON for data storing (with XML as the second most used format). I also bought Easy Save as a very praised solution which uses neither XML nor JSON, but claims to be faster than both (tho i don't care about the fast part, easy got my attentiom) but i don't know how easy is to edit those files since they are in their own enclosed binary format. They have their own editor, but that seems as handy as editing 800 globals in Playmaker (not handy at all ;D).

Why am i asking this now? I'm starting to bump into limitations. The way i work has 0 reusability and making things interesting and with variety is starting to take too much time copying and pasting the same things over and over to get a sense of controlled randomness.

The game i'm working on is an endless shmup and i want to be able to store everything and just call it as needed.

I want to create an enemy that will draw an image, flying pattern, shooting pattern, hp, attack points, armor type, bezier path points and everything else from a data structure in the format that is easy to store, read and edit. Furthermore, i want to be able to easily make subsets and combinations of data. As far as i have seen, for something like that i need multidimensional arrays (probably) and JSON seems the best suited for something like that.

One last thing i need is the advice on most painless way to refactor the existing FSM's and stored global and local variables (exporting and rearranging to empty data structures).

Any advice is more than welcome. I attached a dummy basic data structure of how enemy objects i imagine to work like, it's basically like deriving classes and adding methods.









« Last Edit: November 03, 2017, 04:42:28 AM by krmko »

Dakk

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Need advice on data driven design
« Reply #1 on: November 03, 2017, 09:15:41 AM »
My quick advice which you may already know:

-Don't use global variables unless you absolutely have to- it will save you a lot of time and pain to just follow that rule- I chose to learn the hard way.  Except for a few cases- there is almost always a better design pattern than using a global variable.  I only use them to define my system controller game objects and a few other things.
-Learn and use set fsm var actions to pass data from different fsms- need to tick the "inspector" attribute for the var so they are accessible.
-For instanced game objects you can set and store the data you need on the prefab itself- just add some public vars to a simple script on the prefab.  I've found that is the best way to keep data that is associated with an obj instance.
-Data Maker/Array Maker has a ton of options to load and save data- I read huge .csv of data into my game for inventory/unlockable system then store it in arrays for use- then apply to my game objects as needed- works great (except on UWP).  For tuning and balancing after the AI tests the game overnight I write out a huge .csv which I can analyze conveniently in excel.
-Templates and Run FSM are powerful- great way to keep your fsm's smaller and re-use fsm's. This feature doesn't seem to be widely used- but it is very useful- a bit hard to debug if you nest several templates and there are a few editor display bugs- but still worth exploiting.
-Easy Save is great!  I use it for saving all user data, and also offline in the editor to save out my level data, then load these files at run-time.  Works great, Joel is a pro and very dedicated to support.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: Need advice on data driven design
« Reply #2 on: November 03, 2017, 10:15:36 AM »
Hi,
Indeed json or xml is a good way to go.

You can check out this video (and the other 2 parts) to get familiar with datamaker :


To refactor depends on your setup it's hard to tell.

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Re: Need advice on data driven design
« Reply #3 on: November 03, 2017, 01:39:31 PM »
Luckily, globals can be opened in nice readable spreadsheet format, easily converted to xml, and be used to populate hash tables. Also, xml can be easily edited by ms xml editor. Regarding that, easy save 3 is in beta and is not supporting xml and json until full release comes out (unfortunately, it won't be backwards compatible with es3) and frankly, by watching djaydino's tutorials, i don't think i feel quite comfortable yet with xquery nor i have that amount of data to find that complicated setup useful in the long term.

So, my question is, are hash tables fast and good enough way of storing data? They're quite convient for me and can be easily manually populated.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: Need advice on data driven design
« Reply #4 on: November 04, 2017, 04:03:52 AM »
Hi,
Hash tables should be as fast as arrays,
But good enough depends on what you are using them for.

xml/json would be ideal i think.
May make a new project with datamaker and play around with it so you can understand it better.
There are also some samples included with the package.

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Re: Need advice on data driven design
« Reply #5 on: November 04, 2017, 11:11:22 AM »
As far as i have read, they're basically the same as getting an array item by index number, so that's cool. I'm storing variables and references, simple data types mostly split into several hashtables, so it should be fast as hell since it takes a lot more complicated FSM's to avoid working with globals.

Great idea, i'll play a bit.