Game Development Community

exec command not creating DSO! [SOLVED]

by Andrew H · in Torque Game Builder · 10/02/2011 (7:57 am) · 6 replies

So, I'm making my profile system - it creates a SimObject, writes it to a FileObject, then executes the file it created and deletes the source file, leaving only the DSO - preventing crafty players from tampering with their profile. Concept tests for this method have shown this strategy works.

However, one exec command fails to create a DSO. Here's the code (it includes the test I used to make sure that was actually the problem):

function readProfileNames()
{
   //This is the exec that allegedly isn't working.
   exec("./saveFiles/profileNames.cs");

   //This is the test I used to make sure it really just wasn't creating a DSO.   
   %file = new FileObject();
   %result = %file.openForRead("./saveFiles/profileNames.cs.dso");
   if(%result)
   {
      %file.close();
      fileDelete("./saveFiles/profileNames.cs");
   }
   else
   {
      //And then this error pops up.
      error("It didn't create a DSO!");
   }
   %file.delete();
   
   //In case you're wondering, this is how I am reading the data from my SimObject.
   $profileName1 = profileNames.name1;
   $profileName2 = profileNames.name2;
   $profileName3 = profileNames.name3;
}

#1
10/02/2011 (10:23 am)
compile(%pathToFile);

Is your friend.
#2
10/02/2011 (7:36 pm)
Well, now I've got a completely different problem - my FileObject isn't creating the file to execute (it was before...)!

Here's the code:
function checkProfileNames()
{
   %file = new FileObject();
   //Checks to see if I've already made and compiled the file.
   %result = %file.openForRead("./saveFiles/profileNames.cs.dso");
   if(%result)
   {
      echo("The profile names existed");
      %file.close();
      readProfileNames();
   }
   
   else
   {
      echo("The profile names didn't exist, so I made them");
      %file.close();
      //This creates the data and stores it to the file.
      new SimObject(profileNames){
         name1 = "New";
         name2 = "New";
         name3 = "New";
      };
      
      %result = %file.openForWrite("./saveFiles/profileNames.cs");
      if(%result)
      {
         //This is what it passes - it claims to have successfully opened it.
         %file.writeObject(profileNames);
         %file.close();
         readProfileNames();
      }
      
      else
      {
         error("It couldn't open it for write!");
      }
   }
   //Before you say it - this deletes the FileObject I'm using to create the files to save it in - not the file itself. For that you use fileDelete()
   %file.delete();
}

And when I run the code to compile/exec it, it complains that it's an invalid file - and sure enough, when I check it doesn't exist.
#3
10/03/2011 (6:19 pm)
Scratch that - this only happens when I use the compile command. It just won't create a DSO!

Either way, neither DSO nor source exists when I try this.
#4
10/05/2011 (7:03 am)
Okay - I'm getting fed up with all this stuff here. I'm gonna try XML now.
#5
10/05/2011 (10:43 am)
Before you jump into having to write a parser, make use of some built in engine functions that will save you a great deal of time.

I used to be on board with the fileObject method for saving data, but I discovered a neat little trick.

I'm borrowing a bit of segments from above to demonstrate :P
%dCore = new SimSet(DataContainer);
%details = new SimObject(profileNames){  
   name1 = "New";  
   name2 = "New";  
   name3 = "New";  
};
%dCore.add(%details);  
//This portion is saving
%dCore.save("./saveFiles/profileNames.cs");
exec("./saveFiles/profileNames.cs");
compile("./saveFiles/profileNames.cs"); //This gives you the .dso you want
deleteFile("./saveFiles/profileNames.cs"); //delete the .cs file

That will write the data, to add more fields, just simply pull a NameToID call on the inner container a-la
%details = nameToID("DataContainer/profileNames");
%details.moreStuff = "Another Name";

To load the data up, simply exec the compiled .dso file, to from which you can use my same writing method above to check if the %details object exists or not. Saves time, effort, and hair pulling.

Good luck!
#6
10/05/2011 (3:20 pm)
Thanks, but I've already had success with XML - with built-in T2D functions, no less!