RunTime Eval JS on WebPlayer

Hi all.
I’m trying to modify my GUI ( iGUI) with JS at runtime.
I used to do that with lua on my former engine…

var textAsset : TextAsset;
		 textAsset   =  Resources.Load("GUIScripts/bouton_repeter");  
		eval ( textAsset.text );

Everything works fine on the Editor.
On the webPlayer is quite strange.

I can do stuff like that :

var instance ; 
instance =GameObject.Find("iGUI Root").GetComponent("iGUICode_POC_Neutre2_5");
instance.getInstance().winDocInfo_WIN.setEnabled(true);

But calling set function are not working such as that :

instance.getInstance().winDocInfo_WIN.label.text="Répeter la dernière consigne";

So it’s quite strange , because if i add a TestButton on a JS MonoBehaviour, i can call the set method (but of course it’s compiled code and not runtime code here).

The Error on the WebPlayerLog is :

 Exception caught : CompilationErrorsException: script(2,49): BCE0055: Boo.Lang.Compiler.CompilerError: Internal compiler error: Attempt to access a private/protected method failed.. ---> System.MethodAccessException: Attempt to access a private/protected method failed.

Any idea how can i handle that? May i can only use function and not setter on dynamic JS eval code?
Thanks

I’ve run into exactly the same problem. If I try to access my variables from within an eval’d piece of code, it tells me I’m trying to access private/protected method:

CompilationErrorsException: script(1,30): BCE0055: Boo.Lang.Compiler.CompilerError: Internal compiler error: Attempt to access a private/protected method failed… —> System.MethodAccessException: Attempt to access a private/protected method failed.

Anyone have any suggestions?

I’ve simplified things down to the script below. I have a scene with just a camera, and I drop the script on it. That’s it – simple as can be.

It works fine in the editor, even with a web player target, but the actual web player throws an exception.

I think this may be an actual Unity bug.

#pragma strict

var result : String;

function Start()
{
	var ht = {};
	ht["one"] = 14;
	
	var script = " ht[\"one\"] == 14 ";	
	if (eval(script))
		result = "yes";
	else
		result = "no";
}

function OnGUI()
{
	GUILayout.Label("result is " + result);
}

An even simpler illustration of the problem:

#pragma strict

var result : String = "unrun";

function Start()
{
  result = ""+eval(" 7 == 12 ");  // works in editor and web player
  result = ""+eval(" \"seven\" == \"twelve\" ");  // works in editor, not in web player
}

function OnGUI()
{
	GUILayout.Label("the result is " + result);
}

Is anyone working on this? Am I posting in the wrong place?

I also got a problem with the Web-Player and the eval();
I´t seems not possible to access GameObjects and Functions, the only thing works are var : int :confused:

#pragma strict
var cube : GameObject;
function Start()
{
  cube = GameObject.Find...;
}
function myFunction()
{
  Debug.Log("yeah");
}
function Awake()
{
  eval("myFunction();"); // Dont work anywhere
  eval("cube.transform.position.x = 1;"); // Don't work in webplayer
}

Sry I just brought some more Questions and no Answers :confused:

Sry I don´t have a solution – also worked with the eval()
http://answers.unity3d.com/questions/403779/i-used-the-eval-function-on-web-player.html

I encountered functions also can not be called by eval().

function Start()
{
  eval("MyFunction();");
}
function MyFunction()
{
  Debug.Log("works!"); // NOT
}

The code above works nowhere!

Functions Work :smiley:

here is an example:(modded from code of awesome other guy on other thread)

    var code:String = "print (a + b)";
    var a:int = 3;
    var b:int = 2;
    var printOnUpdate:boolean = false;
     function myFunction()
     {
         Debug.Log("yeah");
     }
    function Start ()
    {
        code = "print ('invoked from start: '+ Mathf.Sin(a - b) )";
        eval(code);
    }
 
    function Update ()
    {
        if(printOnUpdate)
        {
           code = "myFunction();";
           eval(code);
           printOnUpdate = false;
        }
    }
 
    function OnGUI()
    {
        if (GUI.Button (Rect (150, 10, 100, 50), "evaluate"))
        {
           code = "print ('invoked from OnGUI: '+ (a + b) )";
           eval(code);
           a++;
           printOnUpdate = true;
        }
    }