View Single Post
  #8   Spotlight this post!  
Unread 08-11-2002, 18:40
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Quote:
Originally posted by Marc P.
if var=127 then pwm1=127, if var=254 then pwm1=254
Unfortunately, this type of syntax does not work. The only thing after the "then" can be a label to go to if the condition is true. For example:

if (sensor1<127) then dontZeroPWM1
PWM1=127
dontZeroPWM1:

With this code, anytime sensor1 is greater than or equal to 127, PWM1 will be set to 127. When sensor1 is less than 127, the condition is true and the code skips the line that would normally set PWM1.

This is by far one of the most confusing parts of PBASIC and is the reason why many times you will find yourself writing "if not" instead of just plain "if." Once you are able to think of "if" statements as being used to skip portions of code, everything becomes much easier.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php