The forum on this site is closed for new comments and posts. Continue the conversation in the new forum, and learn more here.

Change photo with every hour automatically

  • Hi!

    First you need the current hour as a number (so for example at 22:54 it would return 22). In Javascript, you can simply call

    var currentTime = new Date().getHours();

    Then, make an array of textures to pick from, and use that 'currentTime' variable as the index:

    var currentTexture = script.textures[currentTime];

    And then to set the texture to an Image Component, use:

    script.image.mainPass.baseTex = currentTexture;

     

    Here's the full code including the inputs to use in the Inspector:

    //@input Component.Image image // select the Image Component to display the texture on
    //@input Asset.Texture[] textures // place all your textures here, in order

    var currentTime = new Date().getHours(); // this will be a whole number ranging from 0-23, depending on the time of day
    var currentTexture = script.textures[currentTime]; // this gets the current texture based on the hour
    script.image.mainPass.baseTex = currentTexture; // this applies the current texture to the image component

     

    And this is a screenshot of that script (taken at 22:51 my time), so only the 22nd texture has to be filled to see it in the preview:

    Comment actions Permalink
  • Max van Leeuwen Hey thanks but your scripts shows 1 image in a hour. Is there any way i can add minutes too because i want let say image 1 from 8pm to 8:30pm and image 2 from 8:50pm to 9:24pm. 

    i basically want script with custom time that i can edit myself to change time

    Comment actions Permalink
  • Yeah! The new Date() class has many options, you can see all of them on this page!
    For example, for the current minute of the hour, use

    var currentMinute = new Date().getMinutes()

    Which you could then use, for example, to check if it's between 0-30 or 30-60

    if(currentMinute < 30){
      // first half of this hour  
    }else{
      // second half of this hour
    }

     

     

    If you want a lot of time slots at specific dates, this method would get a bit annoying to work with.
    In that case, I'd advice making a table of epoch times of all the time points you have!
    Epoch times are timezone-independent, it is the amount of milliseconds since January 1st, 1970, 00:00:00UTC.
    So it gives you a really long number, like '1649368198' (this is the time as I'm currently writing this).
    If you use Date.now(), you get the time in epoch format, so checking if another epoch time is in the past or in the future is just a matter of checking if it is lesser or greater than it!
    You can use this website to convert 'human readable' times to epoch format.

     

    Hope this helps!

    Comment actions Permalink
  • Max van Leeuwen

    thanks for this epoch method but this will only work for 1 day so is there any universal method that can work everyday and if yes then can you please provide me the full script as you did in the 1st reply

    btw i saw a script somewhere in which the made difference case that helped them to achieve this can we also do the same?

     

    Also can i know any of your social username or your email so that i can contact you in case i want further help?

    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!