We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have my code set up to choose from a random selection of words. Only problem is, it often chooses the same one more than one time in a row. I want a variable to remove itself after I've chosen it. I'm pretty new to this so apologies if this is fairly obvious. I've put my code in it's current state below, encase that helps. Cheers!
int yPos = 40;
int shuffle = 16;
PFont ourFont;
void setup(){
size(500,250);
background(0,0,0);
ourFont = loadFont("Quicksand-Bold-24.vlw");
}
//click to start
void mouseClicked(){
shuffle = shuffle -15;
}
void draw(){
if( shuffle > 15){
textFont(ourFont);
fill(236 , 0, 140);
text("Click to start.", 170, 125);
}
//move background after 'if( shuffle < 10){' then words stay when integer =10
if( shuffle < 15){
background(0,0,0);
String[] words = {"I've been interviewed on national television dressed as a chicken.", "I've refereed in the world marbles championships.", "I once featured on the TV show 'Animals Do the Funniest Things' getting headbutted by a reindeer.", "I can speak Span(ish).", "I'm learning sign language.", "I like to sea-swim.", "I was once featured in the papers for a book signing when I hadn't read the book.", "My middle name is Nathan.", "I can count to 10 in 5 languages.", "My first TV appearance was at the age of 4.", "I cook a mean Sunday Roast.", "My initials are SnM.", "I can play the drums.", "I skateboard, mountain board and snowboard.", "I'm known for my puns.", "I have a beard.", "I'm 5ft 8 inches tall.", "I like to play table tennis.", "I was once attacked by a fox.", "I like to play pool.", "I like words.", "I've never seen Star Wars.", "I'm a purple belt in Karate", "I can diablo.", "I love hip-hop music.", "I have blue eyes.", "I'm quite hairy.", "I once ran a half marathon with 2 weeks training.", "I love Stroop Waffles.", "My favourite biscuit is a malted milk." };
int index = int(random(words.length));
textFont(ourFont);
fill(255 , 255, 255);
text(words[index], 30, 30, 370, 200);
shuffle = shuffle +1;
}
delay(100);
}
Answers
I can't read your code. Fix plx
https://forum.processing.org/two/discussion/32/how-to-format-text-and-code-on-the-new-forum/p1
Maybe you can use a StringList instead of a String[] array. Then you can remove an entry from from the StringList when it's picked.
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
https://forum.Processing.org/two/discussions/tagged?Tag=shuffle()
is that better?
Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.
Kf
Think that will make more sense for you all!
Thanks.
As I said use a StringList. It has a shuffle() and a remove() method.
https://processing.org/reference/StringList.html
If it's gonna get shuffle(), there's no need to remove() anything.
That is, for another round, shuffle() it over again! ;;)
https://forum.Processing.org/two/discussion/21425/is-it-possible-to-make-my-random-string-appear-all-but-only-one-time-each-during-the-run#Item_7
thanks guys!
you need to move the declaration of the array outside of draw otherwise there is still a chance of duplicates.
the way you have it you have several bags of balls, all numbered 1 to 15 and you choose a ball out of a different bag every time and you could pick ball 1 out of several bags
move the definition of words from line 27 to line 3 then you'll have one bag, and no chance of duplicates. (although you'll have to change your index - it can't be random, should just count)