Search Unity

Please I really need help with building my game!!

Discussion in 'Scripting' started by abdallah123, Sep 27, 2011.

  1. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    Hi,

    I built a game this game works just fine in unity editor but when I built it I got some errors with the OnGUI function while displaying a message it suddenly disappears what could be the problem is there a way to fix this?
    Plus could I have some coding problems even if no bugs or errors are detected by unity?
    Please I really need some help!!

    thank you!!
     
  2. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,289
    Well theres no real info here to help you with ,post some of the problematic code. And yes, you can have bugs that the editor does not know about. Usually , if the editor knows about it , its not a bug , its an error.
     
  3. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    Thank you for the reply but I forgot to mention that when I press the alt tab button and refcus on the game window the messages reappears so I don't think that it's a code error. right?
     
  4. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,289
    It sounds as if you dont have the application set to run in background, you can check this in the Player Build Settings.
     
  5. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    what willc said.
     
  6. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    yeah I did check it
     
  7. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    If this can help I also have a login page and when I run the game for the first time the login button works just fine but when I quit the game and reaccess it and press the login button it doesn't do anything why?
     
  8. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    I have a SQLite database attached to my game is this a good code?:
    Code (csharp):
    1.     function GetConclusion(idm, score){
    2.     var query : String;
    3.     var string1:String;
    4.     connection = "URI=file:Assets/PJI Game.s3db";
    5.     dbcon = new SqliteConnection(connection);
    6.     dbcon.Open();
    7.     query = "SELECT Phrase FROM Conclusion where ID_Mission="+idm+" and Score="+score;
    8.     dbcmd = dbcon.CreateCommand();
    9.     dbcmd.CommandText = query;
    10.     reader = dbcmd.ExecuteReader();
    11.     string1=reader[0].ToString();
    12.     dbcon.Close();
    13.     return string1;
    14.     }
     
  9. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,466
    You do realize there is a log file in your standalone directory where error messages go that would normally go in the Debug if you were in the Editor right? That would at least give you a a message to get started...
     
  10. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    yes I know :) but I am asking because this code works just fine in the editor but i am having troubles in the built game so I am rechecking my codes.but thank you for your reply.
     
  11. riadsala

    riadsala

    Joined:
    Feb 10, 2010
    Posts:
    15


    I'm having a similar problem. For some reason, the standalone build fails to find some GameObjects :( I don't know why the links don't work, as everything runs smoothly in Unity's editor
     
  12. abdallah123

    abdallah123

    Joined:
    Aug 5, 2011
    Posts:
    146
    what is your problem can you tell me in details perhaps I can help you with it cz mine was that the built game was not able to read the database or to access it this was because of the dlls I needed newer versions of SQLite.dll and SQLite3.dll but you're telling me that your game is not reeding some game objects how is that?
     
  13. niks07

    niks07

    Joined:
    Oct 11, 2011
    Posts:
    11
    hello all.

    i am new in unity.

    i want to create a game in which i need to create local database.

    i read many a posts on unity/google but i cant find anything very clear and fast..

    so any one can tell me the clear steps for creating a local database in unity-game for iphone/ipad...???

    here is the code that i used but it only creates the database file while i run it on MAC..

    //==============

    /*--- this code i am using to create database------*/

    import System.Data; // we import our data class
    import Mono.Data.Sqlite; // we import sqlite

    public class dbAccess
    {
    // variables for basic query access
    var connection : String;
    var dbcon : IDbConnection;
    var dbcmd : IDbCommand;
    var reader : IDataReader;

    function OpenDB(p : String)
    {
    connection = "URI=file:" + p; // we set the connection to our database
    dbcon = new SqliteConnection(connection);
    dbcon.Open();
    }

    function BasicQuery(q : String, r : boolean) // run a basic Sqlite query
    {
    dbcmd = dbcon.CreateCommand(); // create empty command
    dbcmd.CommandText = q; // fill the command
    reader = dbcmd.ExecuteReader(); // execute command which returns a reader
    if(r) // if we want to return the reader
    {
    return reader; // return the reader
    }
    }

    // This returns a 2 dimensional ArrayList with all the
    // data from the table requested
    function ReadFullTable(tableName : String)
    {
    var query : String;
    query = "SELECT * FROM " + tableName;
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    var readArray = new ArrayList();
    while(reader.Read())
    {
    var lineArray = new ArrayList();
    for (var i : int = 0; i < reader.FieldCount; i++)
    lineArray.Add(reader.GetValue(i)); // This reads the entries in a row
    readArray.Add(lineArray); // This makes an array of all the rows
    }
    return readArray; // return matches
    }

    // This function deletes all the data in the given table. Forever. WATCH OUT! Use sparingly, if at all
    function DeleteTableContents(tableName : String)
    {
    var query : String;
    query = "DELETE FROM " + tableName;
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    }

    function CreateTable(name : String, col : Array, colType : Array) // Create a table, name, column array, column type array
    {
    var query : String;
    query = "CREATE TABLE " + name + "(" + col[0] + " " + colType[0];
    for(var i=1; i < col.length; i++)
    {
    query += ", " + col + " " + colType;
    }
    query += ")";
    dbcmd = dbcon.CreateCommand(); // create empty command
    dbcmd.CommandText = query; // fill the command
    reader = dbcmd.ExecuteReader(); //execute command which returns a reader
    }

    function InsertIntoSingle(tableName : String, colName : String, value : String) // single insert
    {
    var query : String;
    query = "INSERT INTO " + tableName + "(" + colName + ") " + "VALUES (" + value + ")";
    dbcmd = dbcon.CreateCommand(); // create empty command
    dbcmd.CommandText = query; // fill the command
    reader = dbcmd.ExecuteReader(); // execute command which returns a reader
    }

    function InsertIntoSpecific(tableName : String, col : Array, values : Array) // Specific insert with col and values
    {
    var query : String;
    query = "INSERT INTO " + tableName + "(" + col[0];
    for(var i=1; i<col.length; i++)
    {
    query += ", " + col;
    }
    query += ") VALUES (" + values[0];
    for(i=1; i<values.length; i++)
    {
    query += ", " + values;
    }
    query += ")";
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    }

    function InsertInto(tableName : String, values : Array) // basic Insert with just values
    {
    var query : String;
    query = "INSERT INTO " + tableName + " VALUES (" + values[0];
    for(var i=1; i<values.length; i++)
    {
    query += ", " + values;
    }
    query += ")";
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    }

    // This function reads a single column
    // wCol is the WHERE column, wPar is the operator you want to use to compare with,
    // and wValue is the value you want to compare against.
    // Ex. - SingleSelectWhere("puppies", "breed", "earType", "=", "floppy")
    // returns an array of matches from the command: SELECT breed FROM puppies WHERE earType = floppy;
    function SingleSelectWhere(tableName : String, itemToSelect : String, wCol : String, wPar : String, wValue : String) // Selects a single Item
    {
    var query : String;
    query = "SELECT " + itemToSelect + " FROM " + tableName + " WHERE " + wCol + wPar + wValue;
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    var readArray = new Array();
    while(reader.Read())
    {
    readArray.Push(reader.GetString(0)); // Fill array with all matches
    }
    return readArray; // return matches
    }


    function CloseDB()
    {
    reader.Close(); // clean everything up
    reader = null;
    dbcmd.Dispose();
    dbcmd = null;
    dbcon.Close();
    dbcon = null;
    }
    }

    //============

    /*--- this code i am using to get my GUI on screen------*/


    /* Script for testing out SQLite in Javascript
    This script is a GUI script - attach it to your main camera.
    It creates/opens a SQLite database, and with the GUI you can read and write to it.
    */

    // This is the file path of the database file we want to use
    // Right now, it'll load TestDB.sqdb in the project's root folder.
    // If one doesn't exist, it will be automatically created.

    public var DatabaseName : String = "TestDB.sqlite";

    // This is the name of the table we want to use
    public var TableName : String = "TestTable";
    var db : dbAccess;

    function Start()
    {
    // Give ourselves a dbAccess object to work with, and open it
    db = new dbAccess();
    db.OpenDB(DatabaseName);
    // Let's make sure we've got a table to work with as well!
    var tableName = TableName;
    var columnNames = new Array("firstName","lastName");
    var columnValues = new Array("text","text");

    try
    {
    db.CreateTable(tableName,columnNames,columnValues) ;
    }

    catch(e)// Do nothing - our table was already created
    {
    //- we don't care about the error, we just don't want to see it
    }
    }

    // These variables just hold info to display in our GUI
    var firstName : String = "First Name";
    var lastName : String = "Last Name";
    var DatabaseEntryStringWidth = 100;
    var scrollPosition : Vector2;
    var databaseData : ArrayList = new ArrayList();

    // This GUI provides us with a way to enter data into our database
    // as well as a way to view it

    function OnGUI()
    {
    GUI.Box(Rect (25,25,Screen.width - 50, Screen.height - 50),"");
    GUILayout.BeginArea(Rect(50, 50, Screen.width - 100, Screen.height - 100));

    // This first block allows us to enter new entries into our table
    GUILayout.BeginHorizontal();
    firstName = GUILayout.TextField(firstName, GUILayout.Width (DatabaseEntryStringWidth));
    lastName = GUILayout.TextField(lastName, GUILayout.Width (DatabaseEntryStringWidth));
    GUILayout.EndHorizontal();

    if (GUILayout.Button("Add to database"))
    {
    // Insert the data
    InsertRow(firstName,lastName);
    // And update the readout of the database
    databaseData = ReadFullTable();
    }
    // This second block gives us a button that will display/refresh the contents of our database
    GUILayout.BeginHorizontal();
    if (GUILayout.Button ("Read Database"))
    databaseData = ReadFullTable();
    if (GUILayout.Button("Clear"))
    databaseData.Clear();
    GUILayout.EndHorizontal();

    GUILayout.Label("Database Contents");
    scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(100));
    for (var line : ArrayList in databaseData)
    {
    GUILayout.BeginHorizontal();
    for (var s in line)
    {
    GUILayout.Label(s.ToString(), GUILayout.Width(DatabaseEntryStringWidth));
    }
    GUILayout.EndHorizontal();
    }

    GUILayout.EndScrollView();

    if (GUILayout.Button("Delete All Data"))
    {
    DeleteTableContents();
    databaseData = ReadFullTable();
    }

    GUILayout.EndArea();
    }

    // Wrapper function for inserting our specific entries into our specific database and table for this file
    function InsertRow(firstName, lastName)
    {
    var values = new Array(("'"+firstName+"'"),("'"+lastName+"'"));
    db.InsertInto(TableName, values);
    }

    // Wrapper function, so we only mess with our table.
    function ReadFullTable()
    {
    return db.ReadFullTable(TableName);
    }

    // Another wrapper function...
    function DeleteTableContents()
    {
    db.DeleteTableContents(TableName);
    }

    when i am running his code on MAC it works fine.
    but on i-phone/simulator it cant read the database file and application get crash..

    Thanks
     
  14. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    dude use code tags.... :|