Is There A Way To Have Random Images Populate?
This is a hard one to explain, but after watching the Lens Studio Twitch Stream I had the idea to create a scratch ticket lens, that you would use your hand to scratch off and see the numbers. I wanted to mock up the idea which you can see below, but my ideal state would be to get the numbers to be randomly generated. As of right now, I have two very similar images stacked on top of each other, with you "scratching" off the top one to bring the bottom image and numbers in to view.
What I would like to do is have lets say 7 different images of dollar amounts, be randomly generated into the nine spots. That way each time you scratch the numbers underneath are different.
Example:
If you want to see the lens as it stands right now:
Any help here would be greatly appreciated!
-
Hey Eric,
That's a great idea.
What I recommend is to have 3 layer for your ticket.
First layer would be background which has a table inside but remove the number on it because we want the numbers to be dynamic. It should be something like this:
Then for the second layer we need the numbers to be dynamic so we should use Text object for that.
And we can use javascript to create a random number every time that we load the lens.
You can learn more about the Random in javascript here:
https://www.w3schools.com/js/js_random.asp
And finally the last layer will be the scratch layer. which you already made it working.
Hope this guide will help you and let me know if you have any questions.
Best,
Amir.
Comment actions -
Thanks for the help Amir, truly just getting started and using the resources I am able to get a script to show text on my second layer (The one we want the random numbers on). I am getting stuck in being able to get it to display the random number I want. This is the JS I am using to call a random number between 0-100:
Math.floor(Math.random() * 100);
Here is my inspector Panel on my Second layer
The Print Script I am using is:
But I want it to use the number that is generated from my Random Number Script:
I know it is super amateur hour over here but I am getting a little lost.
Comment actions -
Thanks for the help Amir, truly just getting started and using the resources I am able to get a script to show text on my second layer (The one we want the random numbers on). I am getting stuck in being able to get it to display the random number I want. This is the JS I am using to call a random number between 0-100:
Math.floor(Math.random() * 100);
Here is my inspector Panel on my Second layer
The Print Script I am using is:
But I want it to use the number that is generated from my Random Number Script:
I know it is super amateur hour over here but I am getting a little lost.
Comment actions
Please sign in to leave a comment.
Have a comment?