- Home /
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
Answer by BernieRoehl · Aug 10, 2011 at 06:29 PM
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?
Answer by BernieRoehl · Aug 11, 2011 at 03:28 AM
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);
}
Answer by BernieRoehl · Aug 16, 2011 at 12:16 AM
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?
Answer by daRich · Feb 22, 2013 at 12:44 PM
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 :/
#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 :/
Functions work, see reply at end for code of working funcion.
Answer by daRich · Feb 22, 2013 at 12:43 PM
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!
add "static" before "function", in "eval" say "Scriptname.$$anonymous$$yFunction()". eval wont run as it was in the script, atleast for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220612102951im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Webplayer exception when using BufferedStream 0 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Determining what is causing an unmanged exception in web builds 0 Answers
Camera not working on webplayer like in editor 0 Answers
WebPlayer propagation 0 Answers