We are about to switch to a new forum software. Until then we have removed the registration on this forum.
good days fellas, im wondering why when this array gets to the ewnd it stops ? i would like if it kep looping, now i try to plade the index fork in the constructos of the void loop and i try to run the draw function in the loop in the bracket section and still cant im not sure what is it i should do i try two things i kinda know about, a little help would be big.
What im doing is getting the window to keep repeating it self or continue to keep drawing in the window not in the processing window but in the drawing window, and in the processing windows im going to get a couple of the same print but diff styles one in the array the other in lines and finally each word being print out individually with the ""
String[] words;
String[] lines;
int index = 0;
String konstructor;
void setup() {
size(600, 400);
background(0);
lines = loadStrings("Celebro.txt");
konstructor = join(lines, " ");//in between ",./;']{\|-=+~`@!^%&" delimeter is place
printArray(lines);
println(konstructor);
words = splitTokens(konstructor);//in between ",./;']{\|-=+~`@!^%&" delimeter is place
frameRate(5);//-slow,+fast
}
void draw()
{
background(0);
fill(255);
textSize(64);
textAlign(CENTER);
text(words[index], width/2, height/2);//words[index].toLowerCase(),
index++;
println(words[index]);// printArray(words[index]);
}
Answers
index = (index + 1) % words.length;
im getting this ArrayIndexOutOfBoundException:18 ? what doe it mean Gotoloop? and thanks for the pointer but the issue with that is that it will repeat the window good ! but also in the processing debugging window and that where ill like to be repeated only once and not in a loop, because before you helped me it was getting to the end of the txt document and the window would freeze and not let me X out i can only Stop it from the processing window,
It is not clear what you want, nor what your problem is. Perhaps you would like some basics?
https://forum.processing.org/two/discussion/8093/technical-faq#latest
https://processing.org/tutorials/
Anyway.
is an array. Arrays are like a drawer that stores several different units of the same stuff. Each drawer is accessed by a number id. First is
0
so
is accessing the drawer number 5 (starts with zero)
draw()
is a loop executed 60 times each second. In yourdraw()
you incrementindex
(index++) so each "frame" ( a complete draw cicle ) you get the next drawer, or the String stored in the next drawer..What if you "ask" for a drawer that does not exist? Error. Which Error?
ArrayIndexOutOfBoundException
. Meaning you tried to access a draw that was not created.Lets' step back.
To make an array you need to declare, initialize it, then you can populate it and access stuff stored there...
and so on. you can also do it in some other ways, see FAQ about arrays.
Once you create an array, it has a limited immutable (that's not true, but for now let's assume it is) length. This length is determined by
numberOfSlots
, and can be accessed likeanArray.length
.So you want to stay in boundaries. But you got nothing preventing
index
to go over the length of your array. @GoToLoop used the modulo operator (look in reference) to keepindex
inside desired boundaries.try this
see?
If you need
index
to behave in a different way, you have to work this. As we can't really understand the desired behaviour, we can't help much.It's very common to see arrays accessed inside a
for
loop (reference). It looks some like:You are not doing this, and that's ok, just to mention as you will see this a lot.
Well you'd be better served by reading the stuff I pointed you than my shallow and inexact explanation.
@_vk you must of not understood my title, as it does say im in a basic tutorial by me taking about Daniel Shiffman videos and im also letting you know what video by referencing to that video 18.1, i know about array and i know what the error i got means but what i dont see is why im getting it when im not asking processing to throw a fit when it gets to the end of the array list simply just loop since thats what draw is, if anything i dont understand really what % means or how is used but thats another subject i guess now my thing is that i want to display this in console one time
also i would like just one time in console to print like this one time using println(Words[index]); / printArray(Words[index]);
so that it looks like this
as in right now the program is doing what i want except for the part that it keeps printing on the console println(Words[index]); individually one at a time as it gets called but in a loop the only thing i wan in a loop is the draw words on center of screen
@GoToLoop thats nice thanks but not what i meant as in the txt file is already has the txt in it i just want to display that like so, place all of this in a .txt file so that you can do the ame in both the draw window and console window but in console write just onces and in the draw window keep looping rather then the colors you had
... and in the draw window keep looping...
@GoToLoop i did this which is more of what im looking for
but this is what more of what i want to do just once
solved?
I don't understand this:
but you can for-loop over your array in setup and say
and in draw:
and before setup()
String result = "";