|
Page 1 of 1
|
[ 9 posts ] |
|
Need help with if/then statements
| Author |
Message |
|
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Need help with if/then statements
I'm new to robotc and programming, yet am trying to navigate a maze. The following portion of my code shows errors as listed. Any thoughts on what's wrong?
if (!Walls[0]) { if (Map[MyPosX+RelPosX(LeftOf(MyDir))][MyPosY+RelPosY(LeftOf(MyDir))]==0) NextMove = 0; } else { DecreaseOne(Map[MyPosX][MyPosY]); DecreaseOne(Map[MyPosX+RelPosX(LeftOf(MyDir))][MyPosY+RelPosY(LeftOf(MyDir))]); }
Errors Line 2: Unexpected error token-> '?' Unmatched left parenthesis ')' Expected , found : Unexpected error token : Unexpected error token 0 Unexpected error token , Unexpected ; fund , Unexpected error token ==
other errors The fifth and sixth lines (DecreaseOne) lines have the same types of errors as above. Thanks for any help you can provide.
|
| Thu Feb 18, 2010 11:25 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: Need help with if/then statements
try that instead. You were missing a whole bunch of curly braces. If this is not the intended structure of your code, then you should learn to make better use of indentation. - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Feb 19, 2010 7:24 am |
|
 |
|
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: Need help with if/then statements
Thanks for the previous help. My maze navigation program is getting there, but I'm having one last error with my code. I get the following message in the line " MyDir = RightOf(MyDir);" in the switch statement. **Severe*:Internal:: 'assign location' is same as "expression location' on simple assignment. Recursive proc call of 'cast" may cause this.
|
| Sat Feb 20, 2010 1:53 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: Need help with if/then statements
Well, without knowing what tDirection is, I can't really tell. Perhaps there is a better way to handle this multiple casting thing, it looks really nasty.
Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Sat Feb 20, 2010 2:01 am |
|
 |
|
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: Need help with if/then statements
Here is tDirection. I define North to be the direction the robot is when it enters the maze.
|
| Sat Feb 20, 2010 11:48 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: Need help with if/then statements
What is wrong with using something like: - and - If you are not reusing RightOf and LeftOf, consider inserting the code there directly, it will make your code a lot more readable. Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Sat Feb 20, 2010 12:30 pm |
|
 |
|
LennyB
Rookie
Joined: Thu Feb 25, 2010 2:34 am Posts: 2
|
 Re: Need help with if/then statements
Just curious, but way wouldn't this work? #define RightOf(Dir) (Dir - 1) % 4
if Dir=0, North it will return 3, East, etc.
|
| Thu Feb 25, 2010 3:22 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: Need help with if/then statements
LennyB,
If Dir == 0, you will end up doing (0 - 1) % 4 which is -1, not 3.
- Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Thu Feb 25, 2010 7:53 am |
|
 |
|
alanlevezu
Rookie
Joined: Wed Feb 24, 2010 11:43 pm Posts: 34
|
 Re: Need help with if/then statements
I think it would work better to add 3 instead of subtracting 1. #define RightOf(Dir) (Dir + 3) % 4
|
| Thu Feb 25, 2010 3:40 pm |
|
|
|
Page 1 of 1
|
[ 9 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|