WayneA
USA
Asked
— Edited
Resolved by DJ Sures!
Good Evening,
I am trying to generate a random colour from four predefined colours. The pre defined colours are Red,Blue,Green,Yellow. Please take a look at what I written so far.
:COLOR $1 = "RED" $2 = "GREEN" $3 = "BLUE" $4 = "YELLOW" $COLOUR = GETRANDOM($1,$4) say($COLOUR)
I know why the error I am getting is because the GetRandom is looking for a numeric value. I do not know if the script is capable of what I am trying to accomplish.
EZ-Script is very powerful and can do way more than what you're asking
This is one way to do it...
This is an easier way to do it...
When I was building Jarvis I had him choose his own colour.
This one is a lot more involved than DJ's examples in the fact it will pick a colour, then change it's mind, pick another one etc. until the same colour is picked multiple times. It also gives voice feedback on each pick.
Script is rather old now and may have some errors in due to syntax changing (probably the SayWait() commands) but the idea is there to build off of. It's also a very rough script, I would probably have written it differently today as there are many ways I can see without too much probing that I could have made it a lot less code.
@DJ: Thank You! As the end user, how could I have known to use the DefineArray command?
@Rich: Thank You also for your help.
May I use the scripts posted in this thread in my project?
@Wayne... Using an array is a very common programming technique..... Also, there is lots of example code within ARC to show you how to do all this stuff....
You don't need to use arrays, my example doesn't since I wrote that before I played with arrays. Arrays are a neater method though.
To answer "how would I know to use..." this is, as Richard mentioned, common programming technique. You know by learning, either in a class room, from tutorials and books or from examples.