Are there restrictions on what we can execute in eval()

hi,
I want to emit an event in the eval function where the name of the event is a variable in a script file.

so I want to do the following :

eval(“cc.systemEvent.emit(EventNames.myEvent, “parameter”);”);

however , I get the error : cannot find EventNames.

can someone tell me how I can trigger the above global event with a string parameter?

thanks!

[Note : EventNames is imported in the script file that contains the eval function and myEvent is a valid member variable of EventNames]

you can try

var myEventName = EventNames.myEvent;
eval(“cc.systemEvent.emit(myEventName, “parameter”);”);

eval is global level scope.
Your local variables will not work.

So, first, expose them to global
window.yourX = xxx

Then call it.

But, exposing variables to global and using eval is not a good practice. Just my two cents.