Hi guys,First of all, I have to mention that I'm not from the U.S. and I'm not from England. Therfore, I might have some mistakes, I'll try to write as better as I can.I have to do some project with Lego Mindstroms, which I want to program with ROBOTC (otherwhise, I wouldn't write her at all).Anyway, I need 2D array code but I don't know in 100% how to do that.something like that:

int array [3][5] = {0,0,0,0,0,0,1,1,0,0,1,0,1,0,0}now when the program reads the whole code, when it read "0" than do X action and when it "1" do "y" action (doesn't matter for now what are the actions).

So how can I do it?Thanks

Last edited by newspaper on Mon May 20, 2013 2:26 am, edited 1 time in total.

First of all, I just want to be sure: I know the differences between the definitions of "char" and "int" but why when I'm doing the 2D array I need to write "char" and not "int"?

Secondly, that was written in the debugstream window:

Code:

, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else

Not good... Why it's reapiting too many times? And if its should reapiting over and over again, then why it stopped?I really need your help...Thanks.

Thu May 16, 2013 10:56 am

JohnWatson

Site Admin

Joined: Thu May 24, 2012 12:15 pmPosts: 722

Re: 2D array... I need help

Try adding in a clearDebugStream(); command before you enter the 'for' loops; this will clear the debug stream each time the program is run. Otherwise, the data will be persistent between compiles.

0, 0: we have something else0, 1: we have something else0, 2: we have something else0, 3: we have something else1, 0: we have something else1, 1: we have something else1, 2: we have something else1, 3: we have something else2, 0: we have something else2, 1: we have something else2, 2: we have something else2, 3: we have something else3, 0: we have something else3, 1: we have something else3, 2: we have something else3, 3: we have something else4, 0: we have something else4, 1: we have something else4, 2: we have something else4, 3: we have something else5, 0: we have something else5, 1: we have something else5, 2: we have a 1!5, 3: we have something else

Good, it's better! Thanks, but it's not should be "6,4"?But what should I write instead of "clearDebugStream"? Or I need to keep it there even when I want other actions (like turning on motors etc) will be instead of "writeDebugStreamLine("%d, %d: we have a 1!", i, j)"?

Moreover, I know the differences between the definitions of "char" and "int" but why when I'm doing the 2D array I need to write "char" and not "int"?

Sat May 18, 2013 3:19 pm

Ernest3.14

Professor

Joined: Sat May 18, 2013 1:24 pmPosts: 271Location: Olympia, WA

Re: 2D array... I need help

`int` should work as well. Does it crash?In RobotC an `int` has a larger range than a `char` (-32768~32767 vs -128~127, respectively).

`int` should work as well. Does it crash?In RobotC an `int` has a larger range than a `char` (-32768~32767 vs -128~127, respectively).

No, it's not crashing. Thanks buddy! I changed it.Do you know the answer to the other question?

Sat May 18, 2013 3:46 pm

newspaper

Rookie

Joined: Sun May 12, 2013 3:17 pmPosts: 21

Re: 2D array... I need help! (kinda urgent...).

So... guys, I still need your help. Please.Well, what should I write instead of "clearDebugStream"? Or I need to keep it there even when I want other actions (like turning on motors etc) instead of "writeDebugStreamLine("%d, %d: we have a 1!", i, j)"?

The part you put in the "we got a 1" should be what you'd like the robot to do when it sees an obstacle. Is there anything specific you had in mind?As for char versus int, I just uses chars because it didn't look like you were going to hold very large numbers in there. An int is 2 bytes big and a char is only one byte big. An int's range goes from −32,768 to 32,767, a char is unsigned and goes from 0 to 255.

Edit: I would leave the debugstream there as well as whatever actions you end up putting there. It makes debugging easier

The part you put in the "we got a 1" should be what you'd like the robot to do when it sees an obstacle. Is there anything specific you had in mind?Edit: I would leave the debugstream there as well as whatever actions you end up putting there. It makes debugging easier

= Xander

The thing is that as you saw at the first time when you asked me to do the debug stream it reapted too many times.Therefore, if I just write the action X and Y, then it's happening over and over again like the program doesn't care about the 0's and the 1's, again. So maybe I need to write something like "cleardebugstream" in the beginning to avoid the repeat.

I see one of your Qs has not been answered. Why is it not 6,4 when that's the array dimension? That's an easy one, you see in C (no pun intended), counters start counting at 0, not 1. This may appear a little weird at first, but it explains why you're only going as far as 5,3, which is really the 6th and 4th entry

I see one of your Qs has not been answered. Why is it not 6,4 when that's the array dimension? That's an easy one, you see in C (no pun intended), counters start counting at 0, not 1. This may appear a little weird at first, but it explains why you're only going as far as 5,3, which is really the 6th and 4th entry

case 0:Keep moving the motor1 untill the second touch sensor is pressed. When the second touch sensor is pressed, move back the motor1 untill the first touch sensor is pressed. Then stop motor1. break;

default: }

} }}

This is the code that I need and still it's not working. Instead of words, I wrote the functions of the motors and the loop, of course but it's not working. In this code, it stays on the case 0.HELLLLLLLLLLLLLP!!! So much important and urgant! please!

Thu May 23, 2013 2:26 pm

JohnWatson

Site Admin

Joined: Thu May 24, 2012 12:15 pmPosts: 722

Re: 2D array... I need help! (kinda urgent...).

We will need to see the full code (including what you are doing with the motors); remember, you will be encounter the 0 condition 18 times before it gets to the 1 condition, so whatever you have in the 'case:0' will repeat 18 times in a row. Please provide us with the full code (motor commands included) and we will continue to help debug these issues.

The value of 0,0 is 0The value of 0,1 is 0The value of 0,2 is 0The value of 0,3 is 0The value of 1,0 is 0The value of 1,1 is 0The value of 1,2 is 0The value of 1,3 is 0The value of 2,0 is 0The value of 2,1 is 0The value of 2,2 is 0The value of 2,3 is 0The value of 3,0 is 0The value of 3,1 is 0The value of 3,2 is 0The value of 3,3 is 0The value of 4,0 is 0The value of 4,1 is 0The value of 4,2 is 0The value of 4,3 is 0The value of 5,0 is 0The value of 5,1 is 0The value of 5,2 is 1The value of 5,3 is 0

Edit: On a side note, Xander's provided code works the exact same way (using if statements instead of a switch/case). In this instance, there is no 'superior' method of coding, but it is rather a matter of preference. Just wanted to throw that out there for reference.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum