Whats wrong with this code?

This is my first year doing the programming and I am having trouble with if statements. I know C++, Javascript, regular BASIC but i can’t figure out whats wrong with this.

if (p1_y > 135) then skip:
skip:
relay1_fwd = 1

I used “skip:” because if I just put relay1_fwd = 1 under then, it tells me that it expects a label or something directlyafter then. I have tried it with 135 < p1_y and that doesn’t work either. I have verified that something is hooked up to relay1, so that isn’t the problem. It compiles fine but when I put the y axis on port 1 to greater than 135 nothing happens. I know the joystick works because I have checked it using dashboard.

Also, does white space matter in PBASIC?

Thanks a lot

BTW I have tried this in v1.33 and PBASIC 2.5 the same thing seems to be happening in both.

Relays have 2 variables to control them. So if your other variable (relay1_rev) isnt set to 0 then nothing will happen. If you switch directions elsewhere in the code and you don’t change relay1_fwd to 1 there, then you will have both of the 2 relay variables set to 1 which is an error.

Also, the : after skip in the if then statement line is not necessary.

Why don’t you try a different word than skip. There are some words that you cannot use for labels. Apparently this is one of them. I’m sure you could go look in the manual and find that skip is a different command. I took your code and loaded it into the editor and changed skip and added a random letter after it and the code tokenized.

If the code does not tokenize then I would not run it on the Robot Controller.

if (p1_y > 135) then skip:
skip:
relay1_fwd = 1

In PBasic 1.33 and earlier, if-then branching works like this: if the condition is true, then execution continues at the label following “then”; if it is false, then execution continues at the next statement. In your statement, the label “skip:” comes immediately after the if statement, so it is executed in both cases. Here’s what it should look like:

if (p1_y > 135) then skip:
relay1_fwd = 0 'the “else” case
goto endif: 'without this, execution would just continue at the next line, “skip”

skip:
relay1_fwd = 1 'the “then” case

endif:

Thankyou a lot!!! I did a little changing around and I got it working. :smiley: :smiley: :smiley: :smiley: :smiley: