I’ve this code that lets you type words when keypressed but it only shows one word at the time. I want it to show multiply words (lets say 20) at the time and when word 21 is entered, the first word gets deleted and word 21 becomes 20, and so on and on.
Could somebody help me please? I don’t want to change the way I’ve coded the keys since I need it this way. Thanks in advance! Below is my code!
PFont font;
String myText = "Testing part"; // Starting Text, is only vissable once pressed
String aKPInput = "Medium"; // Input Key : A
String bKPInput = "Is"; // Input Key : B
String cKPInput = "The"; // Input Key : C
String dKPInput = "Message"; // Input Key : D
String eKPInput = "Conversation"; // Input Key : E
String fKPInput = "On"; // Input Key : F
String gKPInput = "We"; // Input Key : G
String hKPInput = "Contact"; // Input Key : H
String iKPInput = "Greenlight"; // Input Key : I
String jKPInput = "Processing"; // Input Key : J
String kKPInput = "Fake News"; // Input Key : K
String lKPInput = "Networking"; // Input Key : L
String mKPInput = "Enlightment"; // Input Key : M
String nKPInput = "Are"; // Input Key : N
String oKPInput = "Concept"; // Input Key : O
String pKPInput = "MAP"; // Input Key : P
String qKPInput = "Walking"; // Input Key : Q
String rKPInput = "Sunshine"; // Input Key : R
String sKPInput = "Greyscale"; // Input Key : S
String tKPInput = "Who"; // Input Key : T
String uKPInput = "Questionmark"; // Input Key : U
String vKPInput = "Probably"; // Input Key : V
String wKPInput = "And"; // Input Key : W
String xKPInput = "I"; // Input Key : X
String yKPInput = "Like"; // Input Key : Y
String zKPInput = "Big Butts"; // Input Key : Z
void setup() {
size(1280, 720);
font = createFont("Sans Serif", 80);
textFont(font, 120);
textAlign(CENTER, CENTER);
}
void draw() {
background(0);
// for (int i = 0; i < wordsDisplay; i++) {
text(myText, 0, 0, width, height);
// }
}
void keyPressed() {
switch(key) {
case 'a': // KEYBOARD A
myText = aKPInput;
break;
case 'b': // KEYBOARD B
myText = bKPInput;
break;
case 'c': // KEYBOARD C
myText = cKPInput;
break;
case 'd': // KEYBOARD D
myText = dKPInput;
break;
case 'e': // KEYBOARD E
myText = eKPInput;
break;
case 'f': // KEYBOARD F
myText = fKPInput;
break;
case 'g': // KEYBOARD G
myText = gKPInput;
break;
case 'h': // KEYBOARD H
myText = hKPInput;
break;
case 'i': // KEYBOARD I
myText = iKPInput;
break;
case 'j': // KEYBOARD J
myText = jKPInput;
break;
case 'k': // KEYBOARD K
myText = kKPInput;
break;
case 'l': // KEYBOARD L
myText = lKPInput;
break;
case 'm': // KEYBOARD M
myText = mKPInput;
break;
case 'n': // KEYBOARD N
myText = nKPInput;
break;
case 'o': // KEYBOARD O
myText = oKPInput;
break;
case 'p': // KEYBOARD P
myText = pKPInput;
break;
case 'q': // KEYBOARD Q
myText = qKPInput;
break;
case 'r': // KEYBOARD R
myText = rKPInput;
break;
case 's': // KEYBOARD S
myText = sKPInput;
break;
case 't': // KEYBOARD T
myText = tKPInput;
break;
case 'u': // KEYBOARD U
myText = uKPInput;
break;
case 'v': // KEYBOARD V
myText = vKPInput;
break;
case 'w': // KEYBOARD W
myText = wKPInput;
break;
case 'x': // KEYBOARD X
myText = xKPInput;
break;
case 'y': // KEYBOARD Y
myText = yKPInput;
break;
case 'z': // KEYBOARD Z
myText = zKPInput;
break;
}
}
yeah sorry man. Realy sorry but I don’t understand anything of what you mean. I’m reading and watching videos about arraylists and how they work but can’t figure it out what you mean by (size)) and a1.set(i) …
It’s stupid to place my wrong codes that I’ve tried but honestly, I don’t understand it and I can’t figure it out.
If you feel like Arraylist is a bit overwhelming, it might be easier to start with arrays instead. Once you get the hang of that you could take another look at Arraylist, because it might be better suited for your situation.
You could see an array as a variable that holds multiple variable values. If we look at the first example on the page I linked just now, it’s similar to:
int number1 = 90;
int number2 = 150;
int number3 = 30;
int a = number1 + number2;
int b = number2 + number3;
In your case you have value for each letter in the alphabet, meaning you need an array size of 26 slots. You could appoint the value of letter a to the first slot, the value of b to the second slot, etcetera, until all the slots in your array are filled.
Using arrays can be handy for many situations. Aside from keeping your data (in your case the words Medium, Is, The, etcetera) compact together, it simplifies certain activities for you. For instance, you can check the length of your array:
I tried to implement the changes you send my in pm:
Atm it only speaks one word at the time, but not the complete array. It also doesn’t have a delay yet.
This is the code so far:
PFont font;
import guru.ttslib.*;
TTS tts;
String[] wordsDisplay=new String[20];
int addIndex=0;
boolean firsttime=true;
String myText = "Testing part"; // Starting Text, is only vissable once pressed
// -----------------------------------------------------------------------------
void setup() {
size(1280, 720);
font = createFont("Sans Serif", 17);
textFont(font, 17);
//textAlign(LEFT);
tts = new TTS();
}
void draw() {
background(0);
for (int i = 0; i < wordsDisplay.length; i++) {
if (wordsDisplay[i]!=null)
text(wordsDisplay[i],
44, 44+i*19);
}
for (int i = 0; i < 2; i = i+1) {
tts.speak(myText);
println("Word " + myText + " is being spoken");}
}
//---------------------------------------------------------------------------
void keyPressed() {
String aKPInput = "Medium"; // Input Key : A
String bKPInput = "Is"; // Input Key : B
String cKPInput = "The"; // Input Key : C
String dKPInput = "Message"; // Input Key : D
String eKPInput = "Conversation"; // Input Key : E
String fKPInput = "On"; // Input Key : F
String gKPInput = "We"; // Input Key : G
String hKPInput = "Contact"; // Input Key : H
String iKPInput = "Greenlight"; // Input Key : I
String jKPInput = "Processing"; // Input Key : J
String kKPInput = "Fake News"; // Input Key : K
String lKPInput = "Networking"; // Input Key : L
String mKPInput = "Enlightment"; // Input Key : M
String nKPInput = "Are"; // Input Key : N
String oKPInput = "Concept"; // Input Key : O
String pKPInput = "MAP"; // Input Key : P
String qKPInput = "Walking"; // Input Key : Q
String rKPInput = "Sunshine"; // Input Key : R
String sKPInput = "Greyscale"; // Input Key : S
String tKPInput = "Who"; // Input Key : T
String uKPInput = "Questionmark"; // Input Key : U
String vKPInput = "Probably"; // Input Key : V
String wKPInput = "And"; // Input Key : W
String xKPInput = "I"; // Input Key : X
String yKPInput = "Like"; // Input Key : Y
String zKPInput = "Big Butts"; // Input Key : Z
switch(key) {
//
case 'a': // KEYBOARD A
myText = aKPInput;
break;
case 'b': // KEYBOARD B
myText = bKPInput;
break;
case 'c': // KEYBOARD C
myText = cKPInput;
break;
case 'd': // KEYBOARD D
myText = dKPInput;
break;
case 'e': // KEYBOARD E
myText = eKPInput;
break;
case 'f': // KEYBOARD F
myText = fKPInput;
break;
case 'g': // KEYBOARD G
myText = gKPInput;
break;
case 'h': // KEYBOARD H
myText = hKPInput;
break;
case 'i': // KEYBOARD I
myText = iKPInput;
break;
case 'j': // KEYBOARD J
myText = jKPInput;
break;
case 'k': // KEYBOARD K
myText = kKPInput;
break;
case 'l': // KEYBOARD L
myText = lKPInput;
break;
case 'm': // KEYBOARD M
myText = mKPInput;
break;
case 'n': // KEYBOARD N
myText = nKPInput;
break;
case 'o': // KEYBOARD O
myText = oKPInput;
break;
case 'p': // KEYBOARD P
myText = pKPInput;
break;
case 'q': // KEYBOARD Q
myText = qKPInput;
break;
case 'r': // KEYBOARD R
myText = rKPInput;
break;
case 's': // KEYBOARD S
myText = sKPInput;
break;
case 't': // KEYBOARD T
myText = tKPInput;
break;
case 'u': // KEYBOARD U
myText = uKPInput;
break;
case 'v': // KEYBOARD V
myText = vKPInput;
break;
case 'w': // KEYBOARD W
myText = wKPInput;
break;
case 'x': // KEYBOARD X
myText = xKPInput;
break;
case 'y': // KEYBOARD Y
myText = yKPInput;
break;
case 'z': // KEYBOARD Z
myText = zKPInput;
break;
}//switch
//
if (addIndex > wordsDisplay.length-1) {
// list is full - we move each element up before adding a new one at the end
for (int i=0; i < wordsDisplay.length-1; i++) {
wordsDisplay[i] = wordsDisplay[i+1];
}
wordsDisplay[wordsDisplay.length-1] = myText;
//
} else {
// list is not yet full
wordsDisplay[addIndex] = myText;
addIndex++;
}
//
}//func
//
The entire list to be spoken on and on. And when entering a new word, pause for a second to start looping again so this way the system couldn’t be overrun.
So when no key has been pressed for 3 seconds, then start entire list to be spoken on and on again. Is that possible?
I haven’t figured it out how to speak the how list at once over and over again. I don’t get the I_speak++; like you suggested implemented in the code :s Any suggestions still left?