Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Load external .txt file works in builder not in web player

Discussion in 'Scripting' started by dansav, Apr 23, 2008.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I have the following code which works fine in the builder.
    But does not work at all in the web player.
    Can you tell me why not?

    var url = "file:///Users/danielsavage/Desktop/CSB/test.txt";
    // Start a download of the given URL
    var www : WWW = new WWW (url);

    // Wait for download to complete
    yield www;

    Debug.Log(www.data);
    eval(www.data);

    The file contains code that sets a gui element.text to a string
    stringToEdit2 = "changed";
    stringToEdit2 = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit2, 25);

    I can see it working in the builder, but it does nothing in the web player.
    The file that unity is running in is the same path but called csb.html

    Thanks,

    Dan
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    In the web player, access to files on the local drive is disabled for security reasons. You can't just let some web page read things from your harddrive, you know :)
     
  3. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    On most systems I've encountered local to local access is allowed.
    Since the player is running locally and so is the file I would think they would be allowed to talk to each other. They are at the same domain.

    So Unity web player does not allow local to local web access for sure?
    That kind of makes developing difficult.

    Thanks,

    Dan
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    In IE7 on Vista and FF3 are executed within sandboxes, so such operations could become impossible.

    Working around that should not be hard. Make a html page and use the WWW Forms and store the data within an MySQL table or a txt on your server, shouldn't be any problem at all.
     
  5. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    In the console for the web player I can see that the debug.log info gets there but then it throws an exception on the next line which is to eval() the text that is sent back. It works running from the builder, but not from the web player. The exception is below...

    var url = "http://192.168.1.110/~danielsavage/CSB/test.txt";
    // Start a download of the given URL
    var www : WWW = new WWW (url);

    // Wait for download to complete
    yield www;
    mydata=www.data;
    Debug.Log(mydata);
    eval(mydata);

    <<this gets through-- the Debug.log of the test.txt..>>

    ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    ----UnityEngine.Debug:Log(Object)
    ----$:MoveNext()
    stringToEdit2 = "hello";
    UnityEngine.Debug:Log(Object)
    $:MoveNext()

    (Filename: /Users/unity-build/Desktop/automatic-build-2/unity/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 1567)

    <<this is where it hangs>>
    DETAILED EXCEPTION END

    ArgumentOutOfRangeException: < 0
    Parameter name: length

    Boo.Lang.Compiler.Pipelines.CompileToMemory..ctor ()
    UnityScript.UnityScriptCompiler+Pipelines.CompileToMemory ()
    UnityScript.Scripting.Evaluator.DoCompile ()
    UnityScript.Scripting.Evaluator.CompileScript ()
    UnityScript.Scripting.Evaluator.Run ()
    UnityScript.Scripting.Evaluator.Eval (UnityScript.Scripting.EvaluationContext context, System.String code)
    Worldsetup+Start$generator$2+$.MoveNext ()

    (Filename: Line: -1867322095)


    Help. Is something wrong with eval() in this case?

    Dan
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    When eval() was first introduced in Unity 2.0, I could only get it to work in the editor. In a later version they fixed it so it works in standalones. I haven't tried it in webplayers until now, but yep, it crashes. I'd say submit it as a bug.

    --Eric