Page 1 of 1

Random text prompt

Posted: Wed Apr 10, 2024 6:10 pm
by Full_Karma
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?

Re: Random text prompt

Posted: Wed Apr 10, 2024 7:05 pm
by kerkersklave
Not sure about your friends code, but I would define a function like this:

Code: Select all

function remove(a, i) { return a.slice(0,i).concat(a.slice(i+1)) }
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:

Code: Select all

remove(array, 3)
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.

Re: Random text prompt

Posted: Sun Apr 14, 2024 9:03 pm
by Full_Karma
I don't understand how I make it work. I tried but I don't get how it's done.

Re: Random text prompt

Posted: Tue Apr 16, 2024 12:31 pm
by schefflera0101
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:

Code: Select all

var randomTextone = ["random 1","random 2","random 3","random 4"]
function randomsay() {
return randomTextone[rnd];
}
var PrompUsed=[0,0,0,0]
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()

:love:

Re: Random text prompt

Posted: Mon Apr 29, 2024 6:07 pm
by Full_Karma
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