We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have an array and need a random spot of it. The problem is, that I need that spot twice so I can't really use
random(ArrayName);
random(ArrayName);
because I would get two different spots. I also can't do
var rand = int(random(0, 4));
arrayName[this.rand];
because the syntax doesn't allow it. I hope you get my point and someone knows an answer. Thanks in advance.
Answers
PS: I can't mark the code pieces as code for some reason ...
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Alright I managed to mark the pieces as code :)
Sorry, but I'm also confused by your question. Need to explain it better. :-\"
Ok so I have stored Vectors in that array and I need one of them (a random one) the problem is that I have to call that function twice because I need the x and the y value of that same Vector. That means I cant use
twice because it would get me two different spots. I neither can use
which would get me the same spot twice (my goal) because the syntax doesn't allow it ... I guess.
Do you have two parallel arrays of type float?
or one array of type PVector?
Your second approach looks good to me:
Still not getting it... Can't you just store the randomly picked p5.Vector in some temporary variable? :-/
BtW, just made an online example sketch, so you can confirm whether that's what you're looking for. :-\"
Visit here for it: http://CodePen.io/GoSubRoutine/pen/dWeaeg/left?editors=001
My complete code is:
I cant use a variable to store the random value, because I can't use that variable to get a spot in the array ....
I can even use a variable with a set value like
But I can't use a variable in which a random value is stored (even if it is an int)
why not?
It throws an error saying something like "x is undefined". The problem is, that x is not undefined and when I use a variable which is not random it works. I can only get a random spot using:
random(ArrayName);
But then I can't use that same spot twice because the spot is not stored in a variable ...
Little Update:
I just fixed the problem with a switch case with a variable of random value. It's a bit complicated but it works... Thank you for you help anyway