NXC NXT 2.0 test_release20111215 file error

Discussion specific to projects ideas and support.
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

NXC NXT 2.0 test_release20111215 file error

Post by h-g-t »

Decided to change the first part of a program which was working but now get a "file error!".

It compiles on both my older version and the latest version of BCC without any syntax errors but only runs down to line 196.

When I press the centre button there is a beep, a very brief pause, then the error message appears.

This is the first time I have used arrays so the problem might be there.

I have tried changing bits here and there but to no avail and am now totally stumped.

What I am trying to do is put names on the left side of the screen, a marker which will either be "+" or " " to the side of each name, and a moving pointer "<<" beside the name currently selected.

It is probably something simple but I just can't see it.

Any assistance would be appreciated.
Scrap ZZ V1-5.zip
Part of file which gives error message.
(2.88 KiB) Downloaded 339 times
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by mattallen37 »

It doesn't look like you set the size of the array "MM_Bool". To do so, you can statically set it while declaring it, like this:

Code: Select all

bool MM_Bool[5];
where the "5" is the number of elements to assign to it. If you want to resize it after declaration, you can use the "ArrayInit" function.

Also, array elements are addressed from 0 through (n-1), not 1 though n, where "n" is the number of elements.

For example, declaring MM_Bool to 5 elements, you address them using MM_Bool[0], MM_Bool[1], MM_Bool[2], MM_Bool[3], and MM_Bool[4].

Edit: and you program should have crashed at line 175 (where you tried to set the value of MM_Bool [1] before initializing the size of MM_Bool).

Edit2:
h-g-t wrote:This is the first time I have used arrays so the problem might be there.
Welcome to the wonderful world of programs crashing because of tiny writing errors, forgotten initializations, and all the rest :| It's worth it though, to be able to address variables by number :D
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by spillerrec »

It is actually not just the MM_Bool variable, but the MM_Text and MM_Display variables too (as they are arrays of strings).
What surprises me is that it doesn't crash when you try to set an element in an array which does not exists, but does crashes when you try to read it again... I'm not using the most up-to-date firmware, but shouldn't it crash at both?

Edit:
Notice that "File error" also gives a number, you get -1 when you try to access an inaccessible element in an array and you get -5 if it cannot create an array because of memory constrains.
Last edited by spillerrec on 17 Dec 2011, 18:49, edited 1 time in total.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by mattallen37 »

I think you're right, it probably should.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC NXT 2.0 test_release20111215 file error

Post by h-g-t »

Thanks for the help.

I have now included a section to initialise the relays

ArrayInit (MM_Text," ",MM_Array_Size)
ArrayInit (MM_Bool,false,MM_Array_Size)
ArrayInit (MM_Display," ",MM_Array_Size)

MM_Text [1] = "<9vRELAY" ; // No if using Mindsensors relay driver
MM_Text [2] = "AUTFOCUS" ; // No if using manual focus
MM_Text [3] = "MIRROR" ; // No if mirror lock off
MM_Text [4] = "BRACKET" ; // No of exposure bracketing not set
MM_Text [5] = "LIMITED" ; // No if shooting limited pano

I no longer get a 'file error' message but the program now loops round (as it is supposed to), beeping every time but the only thing it displays is the '<<' pointer and the battery voltage!

Seems like the contents of MM_Text do not appear.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by spillerrec »

It worked just fine for me, but again, I'm haven't updated the compiler and firmware for some time now. And I cannot test it anymore as I just packed my NXT for transport as I'm going home to my parents for Christmas on Monday...

But you could try changing the ArrayInit()s to initiate to something else than " " like "empty MM_Text" so you can see if it actually writes anything.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC NXT 2.0 test_release20111215 file error

Post by h-g-t »

Thanks, spellerrec, that worked!

But why are the values not getting changed by the subsequent re-assignment of different text to each element?

I have removed the gaps between the array name and the square brackets but that makes no difference.

EDITED

I put values into all the arrays during the initial definition and it worked.

Does that mean that an array which has been set up using ArrayInit can never be changed again?''

EDITED

It seems that the initial values in the array (whether set up initially or using ArrayInit) are not being changed by the subsequent re-assignments.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by mattallen37 »

h-g-t wrote:...
Does that mean that an array which has been set up using ArrayInit can never be changed again?''
...
It seems that the initial values in the array (whether set up initially or using ArrayInit) are not being changed by the subsequent re-assignments.
Unless you use constants, you should always be able to re-assign values of elements.

I don't know that using arrays for strings is really a good idea. I haven't done much of it, as it always seems to give unexpected results. I'd suggest you use 5 "normal" strings, and then if needed, somehow address them with numbers (maybe using a switch).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC NXT 2.0 test_release20111215 file error

Post by h-g-t »

Yes, I think you are right. Been looking around and the answer seems to lie in using the modified firmware, but I want the program to run on any brick with standard software so that is out.

I wanted to use arrays because I hoped to be able to expand it into a routine that I could reuse, but I will just have to make up some program-specific code, probably using cases as suggested.

Thanks for the help.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC NXT 2.0 test_release20111215 file error

Post by afanofosc »

Any 2d array will not work with the standard firmware due to its bug in the REPLACE opcode. You need to use the enhanced NBC/NXC firmware if you want to use 2d arrays. An array of strings happens to be a 2d array since a string is an array of bytes.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests