The forum on this site is closed for new comments and posts. Continue the conversation in our Snap AR Discord server.

Make Things Change on Tap

Featured
  • Hi! I want to change face mask on tap. I don't know much about scripting and all, maybe that's why I'm stuck. I have got eye color, color correction and mask grouped. I want to change all these at once when tap. As you can see I've made 3 groups exactly like that. Please HELP! 

    Comment actions Permalink
  • Hi Divya,

    Are you not able to use the script above? You can set the objects to be turned off and on be "Neon Light", "Neon Lion" and "Neon Stairs" to enable each combo.

    Let me know if you need any clarification.

    Thanks!
    Jonahtan 

    Comment actions Permalink
  • Hi, I am trying to make a lens in which i want to give multiple options for images, i have tried all the scripts i could find but none of them are working for me, please help me if you know the script for it. Thanks.

    Comment actions Permalink
  • Hi mohandhir

    What seems to be the problem?

    Comment actions Permalink
  • Hi, n-mikael
    Thanks for replying
    I used this script, i have also used behaviour script and it doesnt seem to work for me.


    // @input Component.Image image
    // @input Asset.Texture[] textures

    // Our starting texture index
    var currentItemIndex = 0;

    // Assign the initial texture to our image
    script.image.mainPass.baseTex = script.textures[currentItemIndex]

    // Define what happens when you tap.
    function changeTexture () {

    // Increment the current item index
    currentItemIndex += 1;

    // We need the current item index to wrap around
    // once it's higher than the number of items we have.
    currentItemIndex = currentItemIndex % script.textures.length;

    // Change the image's texture
    script.image.mainPass.baseTex = script.textures[currentItemIndex];
    }

    // Bind the function to the touch event.
    var touchEvent = script.createEvent("TapEvent");
    touchEvent.bind(changeTexture);
    Comment actions Permalink
  • Hi,

    I checked out the script and it worked for me 

     

    https://drive.google.com/file/d/18FI9mu_s4taoaPjQDcyWHJkVTPOdGyZf/view?usp=sharing

    Comment actions Permalink
  • Hi, n-mikael

    Thankyou so much, this works for me.

    Comment actions Permalink
  • Don't forget to save the script with Crtl + S

    Comment actions Permalink
  • Hi there, pretty new to scripting and to Lens Studio, I tried to apply your code. The goal is to switch between many makeup models by touching the screen.

    It works fine until it get at the end of the array. I thought it would restart from the index 0 when reaching the last item, but it is stuck on the last item. 

    Did I miss something ?

    Thanks in advance for your help !

    Seb

    Comment actions Permalink
  • Hello, I tried to make a sound switch and it doesn't work for me((

    Comment actions Permalink
  • Lena 

    this script isn't meant for sound its Tap to change on display. make a new thread also so more people can help you with this.

    Comment actions Permalink
  • Lena

    actually never mind I was reading the previous comments and saw he made another one but for audio here it is 

    https://support.lensstudio.snapchat.com/hc/en-us/community/posts/115020451643/comments/360000834386

    // Get an audio component
    // @input Component.AudioComponent audioComponent

    // Get a list of audio files we want to play
    // @input Asset.AudioTrack[] items

    // We remember what item is currently visible.
    // When we start it's the 0th item.
    var currentItemIndex = 0;

    // Play the first sound on initialize
    script.audioComponent.audioTrack = script.items[currentItemIndex];
    script.audioComponent.play(1);

    // Define what happens when you tap.
    function activateNextItem () {
    // Increment the current item index
    currentItemIndex += 1;

    // We need the current item index to wrap around
    // once it's higher than the number of items we have.
    currentItemIndex = currentItemIndex % script.items.length;

    // Set the audio component to play the new audio file
    script.audioComponent.audioTrack = script.items[currentItemIndex];
    script.audioComponent.play(1);
    }

    // Bind the function to the touch event.
    var touchEvent = script.createEvent("TapEvent");
    touchEvent.bind(activateNextItem)
    Comment actions Permalink
  • Hello, ItzJustSamuel.

    Sorry, I didn't specify what I can't do. Yes, I use it and it doesn't work for me. Can you tell me what I'm doing wrong?

    Comment actions Permalink
  • Lena

    The script is outdated, it looks like it doesn't work anymore.

    Comment actions Permalink
  • Thank you, ItzJustSamuel. This sounds very sad.


    I saw in previous messages that the script for replacing the image also did not work and Jonathan Solichin wrote how to update it.

    Is there any way to update this script for audio?

    Comment actions Permalink
  • Hey Everyone!

    Glad to see all the creativity around what you can do with Lens Studio and tapping through objects!

    In the latest version of Lens Studio, you can actually use Behavior to do this now! No more messing around with scripts :) unless you want to!

    First you can create a Behavior that triggers custom triggers:

    The important part here is the "Next in List" option, which allows the "trigger" to call different things every time it's triggered.

    Next you can create another Behavior script where you define what each custom trigger will do, something like this:

    For me, I arrange the scripts like this:

     

    To add Behavior, go to the Objects panel > + > Behavior . You can learn more about it here: https://lensstudio.snapchat.com/guides/scripting/helper-scripts/behavior/

     

    Let me know if you need clarification!

     

    Thanks everyone, can't wait to see what you all come up with!

    Jonathan 

    Comment actions Permalink
  • Hi - I'm SUPER new to this (like a client requested this yesterday and I'm figuring it out as I go). So I have zero clue what I'm doing. What I'm trying to do is be able to flip through face masks on tap. I figured out how to do a one-tap change, but I need to be able to cycle through 8 of them and I'm just not sure where to go next. I'm assuming it needs to be something different than what I'm doing. Any suggestions?

    Comment actions Permalink
  • Hi Roberta, 

    You can use the script in the beginning of this post to provide a list of the face mask you want to change on tap.

    Alternatively, as in your screenshot you can use Behavior. Take a look at the Behavior template in Lens Studio 3.2 to learn more: https://lensstudio.snapchat.com/templates/interactive/behavior/ 

    Cheers,

    Jonathan 

     

     

    Comment actions Permalink
  • Good to know, at this stage I am guess I am trying to future proof and push the box with what Lens Studio's JS can do :) and how to work in certain limitations (dynamic Text, no external API etc.

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!