Error reading textfile in standalone, but working in Editor (csscript host)

Hi,

I’m trying to integrate scripting (http://csscript.net) into my application.

I’ve got it working inside the Editor, but it fails when building a standalone build.

Basically I’m loading this TestScript.cs and executing it:

using System.Collections;

public class TestScript  
{
    public static string Test()
    {     
        return "Yeah !";
    }
}

Opening it like described here http://www.mindthecube.com/blog/2009/11/reading-text-data-into-a-unity-game :

void Start(
{
     try 
       {
               string file = "TestScript.cs";

               DebugConsole.Log(Application.dataPath + "/" + file);
                 	
               System.IO.FileInfo theSourceFile = null;
               System.IO.StreamReader reader = null;
                 
                theSourceFile = new System.IO.FileInfo (Application.dataPath + "/" + file);
                
                if ( theSourceFile != null 
                 theSourceFile.Exists )
                   reader = theSourceFile.OpenText();

                if (reader == null)
                {
                    DebugConsole.Log(file + " not found or not readable" , "error");
                }
                else
                {
                    string myString = reader.ReadToEnd();

                    AsmHelper scriptAsm = new AsmHelper(CSScript.LoadCode( myString, null, false));
                    
                    string result = (string) scriptAsm.Invoke("TestScript.Test");

                    DebugConsole.Log("Result = " + result , "warning");
                }
       }
              
       catch (System.Exception e)
       {
           DebugConsole.Log("Exception = " + e.ToString() , "warning"); 
       }	
}

That works in the editor :

but fails in a standalone build (doesn’t matter if MAC or PC).

My problem is, I’m not quite sure, if that error is Unity related or belongs to the scripting host.

I clearly see the line, but I’m sure , its in the right location (/Content Folder on OSX , /Data on Win), because otherwise my own check, if file exists, pops up.

So, if anyone has an idea, what that error message is about, I really would appreciate some hints. I’m on Unity Pro.

Hope that makes sense,
thanks in advance …

oxl

I want to know too.

You probably should use the StreamingAssets folder for that type of runtime readable data.

The cs file will not be in your “Content” folder , unity will compile all code and compress all assets into data container, where you do not have any file system access.

If you like to have files coppyd unconverted to your Build you have to use the StreamingAssets folder. (Jep there is no folder with that name by default, just create a new folder with the name “StreamingAssets” and dump your file in there.)

It works you way only in the editor, because unity do not compress and strip unused data in the editor.

PS:
If you say ,that the text does not need to get changed at runtime, you could use a TextAsset and link that into a script and use it at runtime.

would you share a mini unitypackage to this .