Hello everyone!
I'm currently working on a new way to store and load user data using .txt files since the current method of storing and loading data in LFSLapper is inefficient and slow.
Here's a small snippet from my source so you can understand what I've done exactly.
Now what I'm wondering is, when I create a new script or a new feature for the insim, I have to create a new variable to manipulate the feature I'm trying to work with, right?
So, I'm wondering how can I make my script detect missing variable in the .txt file and add it to the .txt file so it can correctly store all variables and load them correctly.
I'm currently working on a new way to store and load user data using .txt files since the current method of storing and loading data in LFSLapper is inefficient and slow.
Here's a small snippet from my source so you can understand what I've done exactly.
<?php
IF ($userName != "")
THEN
$userDataName = $userName."_database";
$dataDirectory = "C:\LFS\Server\Insim\bin\default\Databases";
IF (FileExist($dataDirectory,$userDataName,".txt") == 0) THEN
#Create new database file.
CreateFile($userDataName,$dataDirectory,0);
#Add $userName's data in the database file.
PrivMsg($userName,"creating a new database for ".$userName."...");
#Necessary internal variables.
$defUserData[1] = "ExampleVariable1:".$DefUser["ExampleVariable1"];
$defUserData[2] = "ExampleVariable2:".$DefUser["ExampleVariable2"];
$defUserData[3] = "ExampleVariable3:".$DefUser["ExampleVariable3"];
$totalData = 3;
FOR ($Data = 1; $Data <= ToNum($totalData); $Data = $Data + 1)
$Text = $defUserData[ToNum($Data)];
EditFile($userDataName,$dataDirectory,$Text,-1,".txt");
PrivMsg($defUserData[ToNum($Data)]."...Created!");
ENDFOR
PrivMsg($userName,"^7Finished creating new data!");
#Read the database and set the necessary variables.
PrivMsg($userName,"^7Reading...");
$LinesofFile = ReadFile($userDataName,$dataDirectory,".txt");
$NrOfLines = ToNum($LinesofFile["NumberOfLines"]);
FOR ($i = 0; $i <= $NrOfLines-1 ; $i = $i + 1)
$Line = $LinesofFile[$i,"Line"];
$splitData = SplitToArray($Line,":");
SetPlayerVar($userName,$splitData[0],$splitData[1]);
PrivMsg($userName,$splitData[0]."...Loaded!");
ENDFOR
PrivMsg($userName,"^7Finished reading!");
ELSE
#If database file exists, read it and set the necessary variables.
PrivMsg($userName,"^7Loading user data...");
$LinesofFile = ReadFile($userDataName,$dataDirectory,".txt");
$NrOfLines = ToNum($LinesofFile["NumberOfLines"]);
FOR ( $i = 0; $i <= $NrOfLines-1 ; $i = $i + 1)
$Line = $LinesofFile[$i,"Line"];
$splitData = SplitToArray($Line,":");
SetPlayerVar($userName,$splitData[0],$splitData[1]);
PrivMsg($splitData[0]."...Loaded");
ENDFOR
PrivMsg($userName,"^7Successfully loaded all databases!");
ENDIF
ENDIF
?>
So, I'm wondering how can I make my script detect missing variable in the .txt file and add it to the .txt file so it can correctly store all variables and load them correctly.