Help: "Tap to change script", help to edit for "double tap" script instead of "simple tap"

Options
Apprentice
Apprentice Posts: 41 🔥

Hey guys
JS is hard for me!
Trying to understand and modifie scipts, but no. I'm not able.

I just need change "simple tap" by "double tap" in the script.

If anyone can help me to edit it.
Thank you very much

The classic tap to change scipt:
https://support.lensstudio.snapchat.com/hc/en-us/community/posts/4407542450964--Tutorial-How-to-create-a-Tap-To-Change-Lens-

Have fun

Comments

  • audun
    audun Posts: 302 🔥🔥🔥
    Options

    Hi @Apprentice!
    Do you want to override the default Snapchat behaviour of switching cameras, or should the lens change effect as you change camera?

  • Apprentice
    Apprentice Posts: 41 🔥
    edited April 2023 #3
    Options

    I want just to change object. I had some interesting offer by chatGPT, but it often gets the wrong function for LS. I want a double tap because I also have sliders and if I click imprecisely, I sometimes change the object.

  • Apprentice
    Apprentice Posts: 41 🔥
    edited April 2023 #4
    Options

    I think the "tap to change" script can also be interesting to modify for a simple tap => Increment objects + a double tap to decrement objects. In the same vein, I also want to try a Graduated Slider (0 to X number of objects) to change the objects and therefore know where I am in my list of objects.

    Both look good to me and I'm amazed that I haven't seen another request like this in the community. Thank you if you take the time to help me because there are not many people on the forum and even less comfortable with JS. It's a shame, LS is really a good tool to learn Unity for example or JS. I'm a beginner of course

  • audun
    audun Posts: 302 🔥🔥🔥
    Options

    @Apprentice,
    Double-tapping in Snapchat will switch between front and rear camera.
    Do you want the script to disable this behaviour?

  • Apprentice
    Apprentice Posts: 41 🔥
    edited April 2023 #6
    Options

    yes, I don't need this feature with the cameras.
    By blocking double taps and giving a delay between two tap, GPT has already given me a more or less working script. But it's not very responsive.
    Thanks

  • Apprentice
    Apprentice Posts: 41 🔥
    edited April 2023 #7
    Options

    I saw that we could simulate a double tap, by a single tap triggered by a tap itself, but that's nonsense. And I don't want to learn code in these conditions even if nowadays it's fashionable. :p

  • Apprentice
    Apprentice Posts: 41 🔥
    edited April 2023 #8
    Options

    Otherwise, if it's too boring to do because of the native taps, a "slider to change object" would suit me very well too. Or a simple push button that changes my objects instead of the tap on the general screen. This would allow me to limit the object change to the button and not to the whole screen and change by mistake. A numbered slider based on objects would be great, but that must be harder to do. Do the easiest method for you ;) thank you very much and GL

  • audun
    audun Posts: 302 🔥🔥🔥
    Options

    Hi @Apprentice,
    Here's the script that lets you double-tap to change active filters.

    // -----JS CODE-----
    // @input SceneObject[] objectsToToggle
    
    // Prevent default touch event from firing
    global.touchSystem.touchBlocking = true;
    
    var maxDelayBetweenDoubleTap = 1;
    
    var hasRecentlyTapped = false;
    var currentIndex = 0;
    
    script.objectsToToggle[0].enabled = true;
    
    function action() {
        script.objectsToToggle[currentIndex].enabled = false;
        currentIndex = (currentIndex + 1) % script.objectsToToggle.length;
        script.objectsToToggle[currentIndex].enabled = true;
    }
    
    var event = script.createEvent("TapEvent");
    event.bind(function(eventData){
        if (hasRecentlyTapped) {
            hasRecentlyTapped = false;
            action();
        } else {
            delayedEvent.reset(maxDelayBetweenDoubleTap);      
            hasRecentlyTapped = true;
        }
    });
    
    var delayedEvent = script.createEvent("DelayedCallbackEvent");
    delayedEvent.bind(function(eventData)
    {
        hasRecentlyTapped = false;
    });
    

    I'm not sure how to register the first tap faster, so you need to double tap with some time in between. Not a standard fast double-tap.

    Link to Google Drive

  • Apprentice
    Apprentice Posts: 41 🔥
    Options

    Hey
    Wokring fine! :)
    Thank you my friend

  • audun
    audun Posts: 302 🔥🔥🔥
    Options

    No worries! Glad I could help :smiley: