SRL Archive - RS3 Help

How to implement SQLite in a script?


mastah

2014-06-08 13:23:50

I want it to be possible so everyone can see total xp gained by the bot.

I did the following:

DB: integer;
DB := sqlite_open('bot.db');

I get this error:
Exception in Script: Unknown declaration "sqlite_open"

Am I missing something? I have SQLite installed on my pc.

:duh::duh::duh:

Olly

2014-06-08 13:26:42

Simba has SQLite disabled currently.

rj

2014-06-08 15:00:14

you could save the info to a file and load that up

DemiseScythe

2014-06-08 15:14:33

You could gethttp with a php server running MySQL. Then you can use databases with simba. It is a lot more work but if you want a database, I see no other choice currently.

mastah

2014-06-08 15:29:47

From: DemiseScythe
You could gethttp with a php server running MySQL. Then you can use databases with simba. It is a lot more work but if you want a database, I see no other choice currently.


That would be great, do you know any tutorial which explains read/writing data to a MySQL database from simba? I don't have a clue how to do this.

Ian

2014-06-08 15:33:24

From: mastah
That would be great, do you know any tutorial which explains read/writing data to a MySQL database from simba? I don't have a clue how to do this.

http://villavu.com/forum/showthread.php?t=83538

rj

2014-06-08 16:18:27

From: DemiseScythe
You could gethttp with a php server running MySQL. Then you can use databases with simba. It is a lot more work but if you want a database, I see no other choice currently.


writing to a file:

const
currentXP = 5000;

function scriptfileExists():boolean;
begin
result := fileExists(appPath + 'scriptName.txt');
end;

procedure createScriptFile();
var
tmpFile:integer;
begin
if (scriptFileExists) then
exit()
else begin
tmpFile := createFile(appPath + 'scriptName.txt');
closeFile(tmpFile);
end;
end;

function getScriptXP():integer;
var
tmpFile:integer;
s:string;
begin
tmpFile := openFile(appPath + 'scriptName.txt', true);
readFileString(tmpFile, s, fileSize(tmpFile));
try
result := strToInt(s);
except
finally
closeFile(tmpFile);
end;
end;

procedure updateScriptFile();
var
tmpFile, prevXp:integer;
begin
if (not scriptfileExists()) then
createScriptFile()
else begin
prevXP := getScriptXP();
tmpFile := rewriteFile(appPath + 'scriptName.txt', true);
writeFileString(tmpFile, toStr(currentXP + prevXP));
closeFile(tmpFile);
end;
end;

begin
createScriptFile();
addOnTerminate('updateScriptFile');
end.

when the script terminates it will add how ever much xp was gained

mastah

2014-06-09 04:12:12

From: Robert
writing to a file:

const
currentXP = 5000;

function scriptfileExists():boolean;
begin
result := fileExists(appPath + 'scriptName.txt');
end;

procedure createScriptFile();
var
tmpFile:integer;
begin
if (scriptFileExists) then
exit()
else begin
tmpFile := createFile(appPath + 'scriptName.txt');
closeFile(tmpFile);
end;
end;

function getScriptXP():integer;
var
tmpFile:integer;
s:string;
begin
tmpFile := openFile(appPath + 'scriptName.txt', true);
readFileString(tmpFile, s, fileSize(tmpFile));
try
result := strToInt(s);
except
finally
closeFile(tmpFile);
end;
end;

procedure updateScriptFile();
var
tmpFile, prevXp:integer;
begin
if (not scriptfileExists()) then
createScriptFile()
else begin
prevXP := getScriptXP();
tmpFile := rewriteFile(appPath + 'scriptName.txt', true);
writeFileString(tmpFile, toStr(currentXP + prevXP));
closeFile(tmpFile);
end;
end;

begin
createScriptFile();
addOnTerminate('updateScriptFile');
end.

when the script terminates it will add how ever much xp was gained


This is probably the best option, the other one is too bloated.