"Script is undefined"
My code works, but when trying to upload the lens, it gets rejected. No error appears in the debug box, but when I double click the script to open it, I get a little popup box that states:
Script: <path to Script.js>
Line : 5
Char: 1
Error: 'script' is undefined
Code: 800A1391
Source: Microsoft JScript runetime error
Any idea why? The code runs fine and the lens works, but this error is stopping it from being uploaded.
CODE:
// -----JS CODE-----
//@input Component.SpriteVisual vid
var myAnimation = script.vid;
myAnimation.getMaterial(0).getPass(0).baseColor = new vec4(1, 1, 1, 1);
myAnimation.getMaterial(0).getPass(0).baseTex.control.play(1);
Try this > https://support.microsoft.com/en-us/help/308260/how-to-troubleshoot-script-errors-in-internet-explorer
Might not be 100% but, same error.
Are you double clicking the script inside lens studio or just in your file browser? If in your file browser: It appears you have the same problem I had where windows script host is set by default in all new windows 10 installs to run JS files. But it doesn't even support them so you just get an error. Try right clicking and open it with something else.
However this shouldn't prevent the lens from being uploaded.
I tested out your script and I got an error in the console. To fix it I had to change the last line to this:
@Apoc When using the 2 arguments I get the following error:
It is when opening the file in Lens Studio itself, I can still edit the text file fine even when the error occurs. I have never had this problem until I reverted back to factory settings on this laptop. It still works fine on my PC. I'll try upload it with your change to the last line even though it gives an error for me, as that might be what is giving the error on Snapchat's end.
Hi Callum King,
Like Brandon said, it sounds like the javascript file is being opened up by an external program, probably Windows Script Host. When you double click a javascript file in Lens Studio, it opens that file through your operating system, which will use whatever program is associated with .js file extensions. You can ignore that "script is undefined" error message in this case, since it's coming from an external program that doesn't know how to handle scripts meant for Lens Studio.
If you want, you can change your default program for ".js" files to your text editor of choice, like Visual Studio Code or Sublime Text. That way, double clicking on script files will open them in a text editor instead of trying to execute them. Here's a guide for doing that on Windows (step 4 is the relevant part): https://support.microsoft.com/en-us/help/4028161/windows-10-change-default-programs
For the script error you guys are discussing, it sounds like Callum is using a video texture and Brandon is using an animated texture :)
The play method on AnimatedTextureFileProvider takes 2 arguments, while the play method on VideoTextureProvider takes 1 argument. So the 1 argument version will work as long as the texture is a video texture.
I'm not sure what could be causing your submission to fail. Can you tell me the Lens ID for this Lens, found in the "My Lenses" panel? I can get back to you with more information about why the submission is failing.
Hi Jacob,
Thanks for the detailed response! I will change it on my laptop when I next get the chance.
That makes much more sense! I have the VideoTextureProvider yeah with the texture set as the video! :)
For the issue, I could now easily recreate it on my PC but I'm curious about the error. Here's the lens ID: 93521406-5d4e-4396-9c9e-7ed37dd23b70
It's only a very simple lens that was requested by a Reddit user.
Hey Callum King,
Thanks for providing the ID. It looks like the Lens was rejected due to an error from playing a video texture from an invalid state. You can try doing a check like this to make sure the video isn't told to play if it's already playing:
Hope this fixes it for you, let me know if it doesn't. Sometimes errors like this show up during the review process but are hard to reproduce on your own. It might be caused by touch input occurring immediately when the Lens starts or something like that.