The Beginning | page 7 |
Programming for the Genius-Impaired
A series of lessons for those who want to learn how to create their own Lightwave Plugins with Lscript. Winning isn't Everything |
We're still missing some parts in the requester, but we'll stop back and patch that up later (this isn't rocket science, after all). Let's get to the good stuff, determining who wins and who loses! Here we'll visit with our good friend the if/else. mainOpen the champagne! We have a functional (if brutally short) game. You can play it now, but you have only a one in ten chance of correctly guessing the number, and you only get one chance. If we want the player to have more than one guess, we need a way to make our requester repeat. In programming lingo, it's called a loop. A loop is a piece of code that gets keeps on repeating until some condition is met. It is the computer equivalent of the do-over. To make our requester loop, we need another conditional statement. Meet Mr. While You already know this one, too. Parents: While (baby sleeps) Snooze fitfully Kids: While (eyes open) play Grand Theft Auto Fellow Drones: While (Boss nearby) Look busy Freelancers: While (Working two jobs) Lose social life In LScript, that last one looks something like
this: while(jobs == 2)You can probably get the gist of this one. As long as "jobs equals 2," we keep repeating (looping) everything between the brackets, subtracting one from our number of friends each time, multiplying our stress by 2, and never getting a trip to the beach. The vicious cycle doesn't end until we run out of friends and decide to quit a job...};^) Let's apply this newfound knowledge to our program: .main |