Hi, I'm currently using a random text code in my web tease, and I would like to upgrade it,
Here is how it works :
var randomTextone = [
"random 1",
"random 2",
"random 3",
"random 4"
]
function randomTextoneFcn() {
return randomTextone [Math.floor(Math.random()*randomTextone .length)]
}
So one of the random text is picked and used when using "randomTextoneFcn()" in the Edit Eval Tag from the "Say" option.
Then I'll get multiple random texts by changing "one" to "two".
I would like to make the option to select 1 random text and not use it until all the random texts are used, one of my friends gave me this code :
var randomTextbegno = [
"random 1",
"random 2",
"random 3",
"random 4",
"random 5"
];
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array, array[j]] = [array[j], array];
}
}
function displayShuffledArray(array) {
shuffleArray(array);
array.forEach(item => console.log(item));
}
displayShuffledArray(randomTextbegno);
But I don't know how to make it work in the EOS editor. Any idea how to help me?
Random text prompt
- Full_Karma
- Explorer
- Posts: 13
- Joined: Thu Jun 30, 2022 7:11 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Random text prompt
Nicely yours
-
- Explorer At Heart
- Posts: 559
- Joined: Sun Jul 06, 2014 2:11 pm
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Slave
Re: Random text prompt
Not sure about your friends code, but I would define a function like this:
It is very basic javascript so should work in EOS. The function takes an array and removes the given element, returning a modified copy of the array. Call it like this:
You can use the code you have to select an element randomly and then remove it from the array. When you remove the last entry just restore it to the original version.
Code: Select all
function remove(a, i) { return a.slice(0,i).concat(a.slice(i+1)) }
Code: Select all
remove(array, 3)
- Full_Karma
- Explorer
- Posts: 13
- Joined: Thu Jun 30, 2022 7:11 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: Random text prompt
I don't understand how I make it work. I tried but I don't get how it's done.
Nicely yours
- schefflera0101
- Explorer At Heart
- Posts: 124
- Joined: Wed Oct 07, 2020 12:21 pm
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Submissive
Re: Random text prompt
I have a layman's version (I'm sure it works better):
First you define your random prompts
and a variable for the used prompts:
Now the somewhat unfavorable part, because you need several pages for it:
Page1:
if
PrompUsed[0]+PrompUsed[1]+PrompUsed[2]+PrompUsed[3]==4
then
PrompUsed=[0,0,0,0] // set all prompts back to 0, if used.
rnd=Math.floor(Math.random()*randomTextone.length) //chooses random prompt.
//now the query whether it has already been used
if
PrompUsed[rnd]==1
then
Goto Page1
else
PrompUsed[rnd]=1
Goto Page2
Page2:
say: randomsay()
First you define your random prompts
and a variable for the used prompts:
Code: Select all
var randomTextone = ["random 1","random 2","random 3","random 4"]
function randomsay() {
return randomTextone[rnd];
}
var PrompUsed=[0,0,0,0]
Page1:
if
PrompUsed[0]+PrompUsed[1]+PrompUsed[2]+PrompUsed[3]==4
then
PrompUsed=[0,0,0,0] // set all prompts back to 0, if used.
rnd=Math.floor(Math.random()*randomTextone.length) //chooses random prompt.
//now the query whether it has already been used
if
PrompUsed[rnd]==1
then
Goto Page1
else
PrompUsed[rnd]=1
Goto Page2
Page2:
say: randomsay()
- Full_Karma
- Explorer
- Posts: 13
- Joined: Thu Jun 30, 2022 7:11 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: Random text prompt
Yeah my next tease is already mostly finished, I can't use pages this way, but maybe for my next project, I'll use it.
Thanks anyway
Thanks anyway
Nicely yours
Who is online
Users browsing this forum: No registered users and 24 guests