hi guys can you help me…i using sqlite i can play it…but i cant build it…what do you think is the problem
im currently working on windows 32 bit using unity 4.3.4 sqlite3…
using UnityEngine;
using System.Collections;
using System.IO;
using System.Data;
using Mono.Data.SqliteClient;
public class play : MonoBehaviour {
public GUISkin style;
public Texture[] icon;
public string answer;
public string x = "";
public ArrayList Let = new ArrayList ();
public ArrayList letters = new ArrayList ();
public string l = "QWERTYUIOPASDFGHJKLZXCVBNM";
public string c = "";
public string[] files;
public ArrayList exampleFiles;
public string whatToGuess;
public ArrayList isAvailable;
public ArrayList toBeRemoved;
//file
public string word;
public string tagalog;
public string english;
public string complete;
public bool hasRun = false;
public bool[] completed = new bool[6];
public bool fin;
public bool nahulaan=false;
public int cc;
public int lvl;
public bool ok;
public int maxlvl;
void OnGUI () {
if (ok == true)
{
GUI.skin = style;
try
{
//buttons image
GUI.Box (new Rect (370, 330, 100, 30), "");
if(GUI.Button(new Rect(540,288,145,40), "NEXT WORD")) {
Application.LoadLevel(0);
}
if (GUI.Button (new Rect (220,70,150,150),new GUIContent (icon[0])))
{
}
if (GUI.Button (new Rect (380,70,150,150),new GUIContent (icon[1])))
{
}
if (GUI.Button (new Rect (540,70,150,150),new GUIContent (icon[2])))
{
}
if (GUI.Button (new Rect (700,70,150,150),new GUIContent (icon[3])))
{
}
//1st six buttons
if(fin==false)
{
for (int i=0; i<6; i++) {
if (isAvailable [i] == "1") {
if ((GUI.Button (new Rect (400 + ((i % 6) * 45), 250, 40, 40), "" + letters [i])) && (Let.Count < answer.Length)) {
Let.Add (letters [i]);
isAvailable [i] = 0;
toBeRemoved.Add (i);
}
}
else
{
GUI.Button (new Rect (400 + ((i % 6) * 45), 250, 40, 40), "");
}
}
//2nd six buttons
for (int i=6; i<12; i++) {
if (isAvailable [i] == "1") {
if ((GUI.Button (new Rect (400 + ((i % 6) * 45), 293, 40, 40), "" + letters [i])) && (Let.Count < answer.Length)) {
Let.Add (letters [i]);
isAvailable [i] = 0;
toBeRemoved.Add (i);
}
}
else
{
GUI.Button (new Rect (400 + ((i % 6) * 45), 293, 40, 40), "");
}
}
//BOX
for (int i=0; i<answer.Length; i++) {
if (i < 6) {
GUI.Button (new Rect (300 + ((i % 6) * 40), 200, 35, 35), "");
} else if ((i >= 6) && (i < 12)) {
GUI.Button (new Rect (540 + ((i % 6) * 40), 200, 35, 35), "");
}
}
//revert
if ((GUI.Button (new Rect (540, 250, 40, 40), "<"))&&(nahulaan==false)) {
if (Let.Count > 0) {
Let.RemoveAt (Let.Count - 1);
isAvailable [(int)toBeRemoved [toBeRemoved.Count - 1]] = "1";
toBeRemoved.RemoveAt (toBeRemoved.Count - 1);
}
}
//ANSWERS
x = "";
for (int i=0; i<Let.Count; i++) {
if (i < 6) {
GUI.Button (new Rect (300 + ((i % 6) * 40), 200, 35, 35), "" + Let [i]);
} else if ((i >= 6) && (i < 12)) {
GUI.Button (new Rect (540 + ((i % 6) * 40), 200, 35, 35), "" + Let [i]);
}
x = x + Let [i];
}
if ((x == answer)&&(nahulaan==false)) {
string _strDBName = "URI=file:"+Application.dataPath+"/dbfile";
IDbConnection _connection = new SqliteConnection(_strDBName);
IDbCommand _command = _connection .CreateCommand();
string sql;
_connection.Open();
// sql = "CREATE TABLE IF NOT EXISTS words (word VARCHAR(20), tagalog VARCHAR(50), english VARCHAR(50), level INT(), primary key(word))";
// _command.CommandText = sql;
// _command.ExecuteNonQuery();
_command.CommandText = "INSERT INTO answered VALUES ('"+answer+"')";
_connection.Open ();
_command.ExecuteNonQuery();
_connection.Close();
nahulaan = true;
x = "";
}
if(nahulaan==true)
{
//meanings!!
GUI.Box (new Rect (370, 330, 100, 30), "CORRECT!");
GUI.Label (new Rect (200, 370, 300, 50), tagalog);
GUI.Label (new Rect (400, 370, 500, 100), english);
}
}
}
catch(IOException errr)
{
Debug.Log(errr.Message);
}
}
}
// Use this for initialization
void Start ()
{
cc = 0;
isAvailable = new ArrayList ();
toBeRemoved = new ArrayList ();
exampleFiles = new ArrayList ();
string _strDBName = "URI=file:" + Application.dataPath + "/dbfile";
IDbConnection _connection = new SqliteConnection (_strDBName);
IDbCommand _command = _connection .CreateCommand ();
string sql;
_connection.Open ();
sql = "CREATE TABLE IF NOT EXISTS words (word VARCHAR(20), tagalog VARCHAR(50), english VARCHAR(50))";
_command.CommandText = sql;
_command.ExecuteNonQuery ();
_command.CommandText = "select level from words order by level DESC limit 1;";
_connection.Open ();
IDataReader _reader = _command.ExecuteReader ();
while (_reader.Read())
{
maxlvl = _reader.GetInt32(0);
}
_command.CommandText = "select * from lvlmax order by level DESC limit 1;";
_connection.Open ();
_reader = _command.ExecuteReader ();
while (_reader.Read())
{
lvl = _reader.GetInt32(0);
Debug.Log (lvl);
}
_command.CommandText = "SELECT count(*) FROM words WHERE word not in (select word from answered) and level ='"+lvl+"' limit 1;";
_connection.Open ();
_reader = _command.ExecuteReader ();
while (_reader.Read())
{
if(_reader.GetInt32(0)>0)
{
_command.CommandText = "SELECT * FROM words WHERE word not in (select word from answered) and level ='"+lvl+"' limit 1;";
_reader = _command.ExecuteReader ();
while (_reader.Read())
{
word = _reader.GetString(0);
tagalog = _reader.GetString(1);
english = _reader.GetString(2);
}
_connection.Close ();
for (int i=0; i<12; i++)
isAvailable.Add ("1");
ArrayList lstExampleFiles = new ArrayList();
lstExampleFiles.AddRange( exampleFiles );
int d2 = Random.Range (0, lstExampleFiles.Count);
Debug.Log (word);
answer = word;
c = answer;
for (int i=0; i<c.Length; i++) {
letters.Add(c.Substring(i,1));
}
int rr = 0;
for (int i=letters.Count; i<12; i++) {
rr = Random.Range(0,l.Length);
letters.Add(l.Substring(rr,1));
}
letters = ShuffleList (letters);
icon = new Texture[4];
for(int i=0; i<4;i++)
{
icon[i]= (Texture)Resources.Load(answer+"/"+(i+1));
}
ok = true;
}
else
{
if(maxlvl>lvl)
{
//per lvl
Debug.Log("CONGRATULATION. NATAPOS MO ANG LVL : " +lvl);
sql = "insert into lvlmax values("+(lvl+1)+");";
_command.CommandText = sql;
_command.ExecuteNonQuery ();
ok = false;
}
else
{
//all
Debug.Log("CONGRATS YOW. NATAPOS MO");
Application.LoadLevel(0);
}
}
}
}
// Update is called once per frame
void Update () {
}
private ArrayList ShuffleList(ArrayList inputList)
{
ArrayList randomList = new ArrayList();
int randomIndex = 0;
while (inputList.Count > 0)
{
randomIndex = Random.Range (0, inputList.Count-1); //Choose a random object in the list
randomList.Add(inputList[randomIndex]); //add it to the new, random list
inputList.RemoveAt(randomIndex); //remove to avoid duplicates
}
return randomList; //return the new random list
}
}