Had to concentrate a bit to follow that last bit, but I think I'm beginning to understand. This might get hard to follow, but just ask and I'll try my best to clear it up. Here's an overview:
So to make things simple, what I'm attempting to do is randomize each element inside the array.
However the randomization must be limited to only the specific numbers, which are indexes that identify certain specific enemies.
At the present moment, I'm simply substituting that problem to a limit in range between 0 and 3.
The problem here is that Math.random() in my other submission is returning decimal numbers. So the solution is:
Math.floor( Math.random()*3 );
so that the randomization range will be limited to 3 and Math.floor will round the result to the nearest whole number?
However, if I just want to return a specific random element from an array I can just use:
function RandomizeArray(array){ return array[Math.floor( Math.random()*array.length )];
I have MDN pulled up currently, but I'm having a hard time understanding anything in their new layout which I'm starting to loathe.
IF you're multiplying array.length by Math.random(), is Math.random choosing between the elements in that array?
Or is Math.random simply being limited in range like if I were to simply multiply it by 3 like previously? <-- This one I think
Because array.length returns the number of elements in the array, it'll be similar to just multiplying 3 to Math.random.
Say this is the array:
Team[0] = new EnemysTeam(3, 4, 1, 0);
And I want to randomize each individual element in that array. I'm thinking I can start by making those global variables.
Team[0] = new EnemysTeam(E1, E2, E3, E4);
So I'll need to create a function which returns a result defining each individual variable.
I can take another separate array, and use it as a bank for Enemy Indexes.
Say this is the result:
blah[0] = new Indexes( 4, 3, 1. 0);
Now how do I make a function return only one random element out of that array? I'm totally lost there.
Thinking about it, I'll have to use array.length and Math.random to select the element through place value, but how do I return that element?
Looking through MDN, can I use Array.find() in sphere? If so, I can probably do this:
function FindElement() {
var Result = Math.floor( Math.random() * blah[0].length )
return Result * blah[0].find }
So that the result of Math.random returns the place value of the element that array.find will return.
Or does it not work like that? How do you even establish the place value for array.find to look for, if not through multiplication?