Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Where do I place the while(true) in the following script without causing logic errors in run time?

$
0
0
Hello @Hellium! I wanted to thank you for helping me with this project. I appreciate your feedback and have learned a lot about how to use different approaches in using code. I received your message on the use of a while(true) loop and found that I didn't consider what would happen to other aspects of the code that didn't really need to repeat. When I ran the code with while(true) as you'd sent me I found that the count to string was no longer counting the appearances of the sphere or "Apple" prefab because the script was repeating only a count of 1 which makes sense. The word "Apple" being sent to randomOutcomeText.text would also always be the word apple without choosing another word at random, which again makes sense because the script is repeating the first choice due to the while(true) function. I thought that the while(true) would allow the script to choose a new word each time there was a loop but it makes the script not repeat for a different choice. Rather, it repeats the outcome of the first choice exactly and I didn't expect that. I tried separating the random word generator into a different script thinking that if I did that and set it to repeat it would help but I think the result is the same and it just chooses the same word. With that knowledge, I am unsure how to make the generator not repeat the outcome it chose before and instead repeat but be allowed to choose other words randomly. Is there a way to code for random word generation each time rather than a repeat of the first word choice? What I would like is for the random word generator to choose one out of three words at random and if the word "apple" is chosen then the apple or sphere prefab appears and disappears only for the random word generator to randomly choose another word after a certain period of time. If the generator chooses a word that is not "apple" then nothing happens for a certain period of time. Like 16 seconds or something. After 16 seconds is up the random word generator should choose another word randomly again and so on. So whether or not the word apple is chosen, there should be a repeat but like I said, I am unsure how to get the script to repeat without repeating exactly the outcome before. :) How should I set the script (or scripts if I need to make other scripts) so as I can correct for this? I would open and respond to your comments through unity answers through my email but for some reason I am unable to reply back as the link to the page concerning the question is always broken for some reason and my question is removed from the search as well so I can never find it. Weird. Anywho, I found it super funny when I ran the game because I learned something new I wasn't expecting. Randomness is always funny! Again thank you for your time. I appreciate it and look forward to seeing your thoughts on the matter. Have a good evening! Respectfully, -Dlscott1

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>