Author Topic: Class Functions not Working  (Read 852 times)

I wrote some class functions and when I call them they appear not to be defined.
calling sqliteServer("data.db"); and it gives an error saying "Unknown command sql_connect."
What do?

Code:
function sqlite::sql_connect(%this)
{
   if(%this.ip $= "")
      %this.ip = "localhost";

   if(%this.port $= "")
      %this.port = "7212";
   
   %this.onConnect = "SEND CONNECT " @ %this.database;
   %this.connect(%this.ip @ ":" @ %this.port);
}

function sqlite::onConnected(%this)
{
   echo("Connected");
   %this.isConnected = 1;
   %connect = %this.onConnect;
   %this.onConnect = "";

   if(getWord(%connect,0) $= "SEND")
   {
      %this.send(getWords(%connect,1,getWordCount(%connect)));
   }
}

function sqlite::onDisconnect(%this)
{
   echo("Disconnected");
   %this.isConnected = 0;
}

function sqlite::sql_disconnect(%this)
{
   %this.send("CLOSE\n");
}

function sqliteServer(%database, %ip, %port)
{
   %tcp = new TCPObject()
   {
      class = "sqlite";
      ip = %ip;
      port = %port;
      database = %database;
   };
   %tcp.sql_connect();
   return %tcp;
}

when I replaced TCPObject with scriptObject it told me about the no connect (TCP one) function
:C
« Last Edit: March 23, 2013, 09:08:25 PM by Perlin Noise »

I've been staring at this for nearly two hours. And can not find anything wrong. Are you sure there isn't a syntax, or something obvious your forgetting?

I'm not sure myself but perhaps you can use a main script object and create some sort of evaluation method:

Code: [Select]
new scriptObject(SQLO)
{
Class = sqLite;
Connection = new tcpObject()
{
//Tags
};
};

function sqLite::run(%this,%function,%arg1,%arg2,%arg3, ...)
{
%connection = %this.connection;

if(isFunction(%connection,%function))
{
//Evaluate and run TCP OBJECT function
}
else
{
//Error
}

//Code
}
« Last Edit: March 24, 2013, 01:04:01 AM by elm »

It's because you're trying to give a class to a TCPObject. You should consider these two solutions:

Code: [Select]
%tcp = new TCPObject(sqlite)
{
ip       = %ip;
port     = %port;
database = %database;
};

Code: [Select]
%tcp = new ScriptObject()
{
class    = "sqlite";
ip       = %ip;
port     = %port;
database = %database;
};

It's because you're trying to give a class to a TCPObject. You should consider these two solutions:

Code: [Select]
%tcp = new TCPObject(sqlite)
{
ip       = %ip;
port     = %port;
database = %database;
};

Code: [Select]
%tcp = new ScriptObject()
{
class    = "sqlite";
ip       = %ip;
port     = %port;
database = %database;
};
oh, thanks.