playMaker

Author Topic: PM & SQLite Kit Questions  (Read 9409 times)

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
PM & SQLite Kit Questions
« on: July 01, 2013, 10:23:57 AM »
Hi!
I just got SQLite Kit and try to make my game "Dungeon Memory" a bit more dynamic.

I started with the demo file and I can read values from my spanking new database, but I have a problem looping the "Read Database" in the example files for SQLite. I watched the videolink provided on the "documentation" and it explains how the demo works, but nothing about the SQL language. I tried the link to the SQLite docs, but they are gibberish to me.

The provided command is: SELECT * FROM Level1 WHERE id=?
Level 1 is my table, and it reads the value that is inside the "Bind" action.
So I can get the values from one row, but then it stops, no matter how clever my "loops" are made.

How does one make a  read db - put values in variables loop with PM and SQLite Kit?

/s

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #1 on: July 03, 2013, 02:21:04 AM »
Hi,

 Why do you want to loop the sql query? You want to loop the result of the query I guess, right?

Get all from level1 "SELECT * FROM Level1", and then loop inside playmaker.

 Also, why do you want to loop? there maybe a better way, so if you could explain your need, I might have options for you.

bye,

 Jean

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: PM & SQLite Kit Questions
« Reply #2 on: July 04, 2013, 05:29:28 PM »
Hi!
Thanks for your reply.
I wanted to loop because I´m a total noob as it comes to SQL and db in general.

I thought (wrongly I presume) the example file that came with SQLite Kit just pulled one item from the database and that I had to iterate it myself,as the example database just contains one item. I understand that it is just a demo, but a database with just one item seems a bit weird as an example for a database ;) It could perhaps be at least two or three items "got"?

I just wanted to read the data and put into my own variables.

If I understand correctly the select file you posted reads all items in one "action"? I think one could consider that most people using PM is not really programmers  and need some extra handholding with examples that could relate more to "game" type needs.

Thanks for your help though, and thanks for making such a great product.
I am having a lot of fun figuring out who to build stuff with PM. This Sql stuff just went right over my tiny little head..




Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: PM & SQLite Kit Questions
« Reply #3 on: July 04, 2013, 06:07:26 PM »
Yes, I want to put the results into corresponding variables.

I have one column called "BrickType" where I want to store the names of "bricks" into string variables, STR_BrickType01, STR_BrickType02, etc..

I have another column called "BrickAmount" where I want to store the amount of "Bricks" of a certain "BrickType" in INT variables such as INT_BrickAmount01, INT_BrickAmount02, etc..

I want to fill out this "Table" with 32 rows, and probably a lot more columns where I want to store more data needed to create a level.

At the moment I use "ArrayMaker" to do this in several Hashtables, but they are very hard to edit for me with a lot of scrolling up and down and comparing entries, as each array only has one datatype. I want to use a spreadsheet such as googledocs (as advertised for SQLite Kit) to edit the data and import this into Unity and PM to drive the content of my levels and ultimately my whole game.

I think I got some of the concepts totally wrong though, so I am kind of stuck knowing I got the tools to do this, but not the skills.

tal1m0n

  • Guest
Re: PM & SQLite Kit Questions
« Reply #4 on: July 04, 2013, 07:12:18 PM »
Sqlite must becoming popular I just picked up a copy recently myself.

A lot of aspects of this "easy" plug in went over my head as I can get information out of the database but how to turn it into a normal variable that can be accessed in the FSM's?

Wish there was some better tutorials.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #5 on: July 05, 2013, 03:43:33 AM »
Hi,

 This is indeed a common issue to be very careful with. Using Databases, in any kind of software or context requires that you educate yourself as to what is a database, how to build it's structure to fit the needs and how to work with it at run time ( how to query the database to get what you need at particular point in your game).

So the first stop right now for you guys are tutorials on what is sqlite:

http://zetcode.com/db/sqlite/select/

The tricky part is to create your database structure, that comes also at a price and some headaches at first, BUT DON'T GIVE UP, it's a concept to grasp and we all went down that road of wtf is this and why on earth do I need to learn and digest all this... :)

So read this very accuratly. And if some concepts are too hard, don't worry, and try it, run some tests, build them tables within Unity as part of the learning path, and don't try to apply what you are learning directly into your project, that never works ( at least never for me...) . First grasp the concepts, and then you may have further questions because your project as this particular feature not actually explained clearly in the tuts you found so far.

http://zetcode.com/db/sqlite/introduction/

Also as a first advice, naming bricks with incrementing numbers is not really good, instead try to give it proper names representing what they are, maybe by colors, or patterns, or shape, this will be FAR easier to debug when you'll be half way down your project and some issues arises, if you only see 01, 02 04 05, 01 03... that will be very difficult indeed...

Bye,

 Jean

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: PM & SQLite Kit Questions
« Reply #6 on: July 05, 2013, 04:32:29 AM »
Checked out the links. So how would you retrieve  the whole list of cars and costs and display them in playmaker? That example would be most helpful. I understand the commands sent to the database, just not how to do it in pm, as the demo just uses one row of data. If it used two rows I could grasp it.

 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #7 on: July 05, 2013, 07:53:14 AM »
Hi,

 ok, I think you need to contact Orange tree, cause from the screenshot, I can actually already see that the demo indeed hanldes a list of items retrieved from a table, not just one item. Maybe you are not fully grasping yet how Step is working?

as for outputing into a UI of some sort, it very much depends on what framework you are going to use. Typically, Unity gui will not be possible, since within PlayMaker, gui is only executed within the states, so you would not be able to display a list of items this way.

Can you give me more details about the ui framework you plan on using?

bye,

Jean

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: PM & SQLite Kit Questions
« Reply #8 on: July 05, 2013, 09:04:30 AM »
I use NGUI.
Yeah, step is a mystery. First I placed my loop there, but nothing really came out, certainly because I was doing it wrong.

I am just "shotgunning" and trying everything I can think of, but it is frustrating as there is a way of doing it that you or Oksana can do a screenshot of in 5 minutes, Im sure of it.

I figure most of the problems I have, are the same problems most PM users have. If we could code for real, we wouldnt need to use PM, at least not to the extent we are at the moment. But most examples are made by programmers for programmers.



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #9 on: July 09, 2013, 03:00:19 AM »
Hi,

 Yes, databases is a bit of a problem when it comes down to vulgarisation for non programmers.

"step" is a paradigm. imagine all your entries in your database result, Step will give you access to the next entry, until there is no more, it's like "next item" basically.

I'll see if I can make an example using a database and ngui to feed some ui list.

Bye,

 Jean

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: PM & SQLite Kit Questions
« Reply #10 on: July 09, 2013, 07:12:48 AM »
You are a Prince among Men!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #11 on: July 12, 2013, 03:24:24 PM »
Hi,

 Please go and download the playmaker ngui examples for a working scene where table content is loaded using playmaker :)

https://hutonggames.fogbugz.com/default.asp?W1111

 open the "Example 9 PlayMaker Table", it's based on example 9 of ngui.

in your case, the difference will simply be that you get the details from your database, and the process will be identical actually, you will iterate using "STEP" event and add a child to the ngui table.

this example is quite advanced, because I wanted to keep everything that was in that example. So a lot of tricks and feature is provided here.

-- you'll notice that the coloring is kept, so you can leanr how to build complex strings to feed ngui with rich text for it labels

-- I kept the row design intact, it meant that the description, which is disabled by default has to get its content when it's enabled, which means some by pass, the description is first hosted on the row game object, ready to be accessed by the description label when activated. for this I added two new actions to parse and encode colors from unity colors to ngui colors.

 -- you'll notice that I force the description gameObject deactivation at start, because when you instance prefabs, Unity really mess up and simply ignore the activation state and activate everything... this is bad and require this kind of work around.

-- you'll notice also, that I force repositionning of the table, after I added all the rows, failing to do so will result in a visual mess.

-- adding gameobjects as childs of a ngui table ( or any ngui elements), will also results in visual mess, that's why I added the custom action "NguiToolsAddChild", this is a special ngui method that you must call for any parenting.

-- WARNING: when you work with ngui prefab, NEVER drop them outside ngui panels or elements, it will corrupt the prefab. so in this case, if you must edit the prefab in the scene, drop it as a child of the table so that everything stays nice, simply delete it when you are done.

All in all, don't hesitate to ask questions on things you want me to clarify or explain further. if you can understand and redo this scene from scratch, you will have all the skills needed to do anything with ngui and playmaker.

bye,

 Jean

tal1m0n

  • Guest
Re: PM & SQLite Kit Questions
« Reply #12 on: July 12, 2013, 09:45:29 PM »
Jean,

what you were saying about not trying to immediately drop it into a project but instead experiment with each element was of sqlitekit was spot on.

Now that i've played around with it the process seems very straight forward.

You have helpful answers to 90%+ of the questions on this board. Playmaker team should start paying you full time wage as an Q&A employee.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PM & SQLite Kit Questions
« Reply #13 on: July 15, 2013, 01:59:46 AM »
:)

They almost do actually. Alex Chouls is hiring me to provide constant support here. So you can thank him for injecting back a lot of resources into helping you as much as we can.

Bye,

 Jean

meaphly

  • Playmaker Newbie
  • *
  • Posts: 26
Re: PM & SQLite Kit Questions
« Reply #14 on: May 29, 2014, 10:19:07 AM »
Is this SQLiteKit able of reading an online .db when you launch an application or it does this function only in the Editor?
Would I be able to retrieve the db using www and importing on the fly?

Thanks