]Hi,
I am writing some code to work arrays. It shouldn't be too hard, still I run into some problems.
If I try to assign a value like this..
arrTest[1] = "Greetings"
... the value is not assigned.
I tried to use "ArrayReplace()" but I get an errormessage because this function does nog exist althoug the website (brixcc) does show an explain it.
So : How do I assign a value to an array-element?
Merijn
array-issues
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: array-issues
What type is the variable "arrTest" (how did you declare it)?
Typically I only use arrays to hold numbers, not text. I use each element to contain one number.
Each text character is equivalent to an 8-bit number (typically represented by it's ASCII number), so a string is actually an array of 8-bit numbers (NULL terminated).
NXC does support multi-dim arrays, including of type "string", so it should be possible to do what you want. It all depends on how you declared the array (or re-initialized it).
Typically I only use arrays to hold numbers, not text. I use each element to contain one number.
Each text character is equivalent to an 8-bit number (typically represented by it's ASCII number), so a string is actually an array of 8-bit numbers (NULL terminated).
NXC does support multi-dim arrays, including of type "string", so it should be possible to do what you want. It all depends on how you declared the array (or re-initialized it).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: array-issues
If you don't have ArrayReplace then you probably have an old compiler. Are you running on Windows with BricxCC or on Linux or Mac OS X? If you are running on Windows have you updated to the latest test release from http://bricxcc.sourceforge.net/test_releases/?
More importantly, you probably are not using the enhanced NBC/NXC firmware which is required if you want to be able to use arrays with more than one dimension. A string array is actually a two dimensional byte array. The standard LEGO firmware only supports arrays with one dimension - at least with respect to the REPLACE opcode which is what gets used when you try to change the value of an item in an array.
In any case, if you are using the enhanced NBC/NXC firmware then you will be able to use multi-dimensional arrays, including arrays of strings.
It is also possible that your code is having trouble due to some quirks with how NXC handles array declarations/initialization but that usually leads to runtime aborts rather than simply a value in an array not being replaced like it should have been.
John Hansen
More importantly, you probably are not using the enhanced NBC/NXC firmware which is required if you want to be able to use arrays with more than one dimension. A string array is actually a two dimensional byte array. The standard LEGO firmware only supports arrays with one dimension - at least with respect to the REPLACE opcode which is what gets used when you try to change the value of an item in an array.
In any case, if you are using the enhanced NBC/NXC firmware then you will be able to use multi-dimensional arrays, including arrays of strings.
It is also possible that your code is having trouble due to some quirks with how NXC handles array declarations/initialization but that usually leads to runtime aborts rather than simply a value in an array not being replaced like it should have been.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 8
- Joined: 27 Jun 2012, 13:43
Re: array-issues
Hi,
I installed the Nxc/NBC firmware and it work perfrectly.
Indeed I was running the standard 'LEGO"-firmware.
Thank's for the replies
I installed the Nxc/NBC firmware and it work perfrectly.
Indeed I was running the standard 'LEGO"-firmware.
Thank's for the replies
Who is online
Users browsing this forum: No registered users and 0 guests