- Home /
have error on my database script
i have some trouble on my program
it error "NullReferenceException: Object reference not set to an instance of an object
MapLock_Chapter1.Start () (at Assets/Script/MapLock_Chapter1.js:28)"
this is my code that error
#pragma strict
import System.Data;
import Mono.Data.SqliteClient;
private var connection : String;
private var dbcon : IDbConnection;
private var dbcmd : IDbCommand;
private var reader : IDataReader;
var nextLevel:String;
var texturelock : Texture2D;
var textureunlock : Texture2D;
var QuitButton:boolean;
var chapterUnlocked : boolean;
var chapterlocked : boolean;
var needitem:GUIText;
var text:String = " Gather 100 Diamond to unlock ";
function Start(){
connection = "URI=file:" + "23.s3db"; // we set the connection to our database
dbcon = new SqliteConnection(connection);
dbcmd = dbcon.CreateCommand(); // create empty command
var cmdSql = "SELECT diamond FROM test";
dbcmd.CommandText = cmdSql; // fill the command
dbcon.Open();
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
while( reader.Read() ) {
var pdiamond : int = int.Parse(reader["diamond"].ToString());
chapterUnlocked = ( pdiamond > 99);
chapterlocked = ( pdiamond < 100);
print(pdiamond);
}
}
function Update () {
}
function OnGUI ()
{
if (chapterlocked)
{ guiTexture.texture = texturelock;
needitem.text = text; }
if (chapterUnlocked)
{ guiTexture.texture = textureunlock; }
}
function OnMouseUp ()
{
if(QuitButton)
{ Application.Quit(); }
else
{ Application.LoadLevel(nextLevel); }
}
plz help me
thank you.
Comment
Please don't put your question within the script, it's very frustrating to figure out line numbers.
Your answer
![](https://koobas.hobune.stream/wayback/20220613094320im_/https://answers.unity.com/themes/thub/images/avi.jpg)