What previous posters have said to solve your problem...
I think you've slipped up with your syntax...
kelyanok wrote: ↑
Mon Apr 06, 2020 2:00 pm
so im making a game where you need to draw something random in a list. so on mouseUp, the app needs to pick a random word to draw and display it in a field. i wanted to do something like
Code: Select all
put random(10) into rRandom
if rRandom is x
put the x word of field "drawsList" into field "whatToDraw"
without success. i wanted to add a list of things to draw in the fld "whatToDraw", and then this code chooses randomly a word in this list.
is there a way to do that? thanks
There's really no need to do the "if rRandom is x" statement. It acts as a check, and there's no need to check. You know what's in rRandom, a random number between 1 and 10, as you have just made that happen. Just make sure that the list of things you have to draw is at least 10 things long, and understand that anything after 10 won't ever get selected. There are other ways of handling the situation where the drawlist field has more or less than 10 items, such as "put random(the number of items in field drawlist) into rRandom".
The x in the "if rRandom is x" doesn't really mean anything. It's checking if the item in the container rRandom is the letter x...
In the line "put the x word of field "drawsList" into field "whatToDraw" " your words are a little out of order. if you check the other poster's syntax, it should read "put word x" not "put x word", which will read "put word 1 (or any number chosen) into field", not "put 1 word..." See the difference?
What you'll notice in the code provided by the other posters is just a compressed version of what you're doing. Getting the random number and using it all in one go.
Hope that helps.