I have an Array that is populated with names. I also have a random range that will print in console 1 of those names randomly, which is ideal for what it want to do, but now i’m stuck.
My problem is how do i get my randomly picked names so i can be able to make conditions based on the value. I can only print the name so far.
here’s my code :
function Start()
{
var MyArray = new Array(“AntiGrav”, “Boost”, “CosmicShower”, “SkillStop”, “Stopper”, “TractorBeam”);
You my have to expand on your post here, It’s not clear what exactly you’re trying to achieve. You have already made a randomizer for your array, and are printing out the name in the debug.log. What conditions are you wanting to change based on this?
You could always start with
if( MyArray[MyIndex] == "AntiGrav" )
{
// Do Something here
}
If you’re mainly dealing with string states for your character though, an enumerator would actually be more suitable in my opinion so you can set up a switch case statement to execute your code. It’s the same purpose, but a lot easier to work with if you’re not adding any additional conditions to the array. If you wanted to add additional conditions to the array, then you would either have to create a multi-dimensional array, or make a class that has a constructor that holds the values for you.
The class method would be much more advanced, cause you’d probably be making an array of classes which may be hard to understand if you’re new to scripting / programming. Look up javascript enumerators, I’d show you if I were familiar with javascript syntax but I’m not, so I may make a mistake.