Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:43 16 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Array Question

Author Message
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 01:43am 09 Dec 2020
Copy link to clipboard 
Print this post

Hi

I am bring over my C code to CMM2 and I have looked at the docs but an not clear on what I am doing wrong. My C code is like this

#define MAPWIDTH        20  // width of map in tiles
#define MAPHEIGHT       15  // height of map in tiles
int Map[MAPHEIGHT][MAPWIDTH] =
{
{00,52,00,00,26,00,52,53,26,00,16,00,00,00,03,00,00,26,00,00},
{16,15,14,33,26,33,33,00,26,00,16,15,14,16,03,16,16,16,32,00},
{16,16,16,03,15,03,15,00,26,00,00,00,00,16,03,00,00,00,16,03},
{53,00,00,03,16,03,16,16,15,13,17,14,03,16,03,17,15,16,00,03},
{33,00,51,03,16,03,16,53,03,00,00,00,03,16,03,00,00,16,03,16},
{17,00,00,03,16,03,16,00,03,13,17,15,14,16,51,16,03,16,03,02},
{16,13,13,15,16,03,16,00,03,00,00,16,03,00,00,32,03,16,03,00},
{34,00,00,00,00,03,16,52,16,16,03,16,03,13,03,15,13,17,14,03},
{16,03,16,13,16,16,27,25,00,53,03,16,03,16,03,16,00,00,16,03},
{02,03,16,16,00,00,16,26,00,00,03,16,03,16,03,16,16,03,16,03},
{02,03,32,00,00,16,53,26,00,00,03,16,03,16,03,51,00,03,16,03},
{02,15,14,16,13,17,00,26,00,32,03,00,03,16,03,00,04,03,16,03},
{02,27,27,27,27,27,27,25,17,13,14,15,16,13,16,17,14,13,16,03},
{02,00,52,00,00,52,52,26,52,52,00,52,00,00,52,00,00,52,00,03},          
{13,17,15,13,16,15,13,13,17,03,15,13,17,13,15,17,13,14,13,17}
};


In CMM2

DIM MapData(20,15)
data 00,52,00,00,26,00,52,53,26,00,16,00,00,00,03,00,00,26,00,00
etc

then below I do

for j = 0 to 20
 for i = 0 to 15
    read MapData(i,j)
 next i
next j


Is this correct?

Thanks
RC
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 478
Posted: 02:08am 09 Dec 2020
Copy link to clipboard 
Print this post

  RCMAN said  Hi

I am bring over my C code to CMM2 and I have looked at the docs but an not clear on what I am doing wrong. My C code is like this

#define MAPWIDTH        20  // width of map in tiles
#define MAPHEIGHT       15  // height of map in tiles
int Map[MAPHEIGHT][MAPWIDTH] =
{
{00,52,00,00,26,00,52,53,26,00,16,00,00,00,03,00,00,26,00,00},
{16,15,14,33,26,33,33,00,26,00,16,15,14,16,03,16,16,16,32,00},
{16,16,16,03,15,03,15,00,26,00,00,00,00,16,03,00,00,00,16,03},
{53,00,00,03,16,03,16,16,15,13,17,14,03,16,03,17,15,16,00,03},
{33,00,51,03,16,03,16,53,03,00,00,00,03,16,03,00,00,16,03,16},
{17,00,00,03,16,03,16,00,03,13,17,15,14,16,51,16,03,16,03,02},
{16,13,13,15,16,03,16,00,03,00,00,16,03,00,00,32,03,16,03,00},
{34,00,00,00,00,03,16,52,16,16,03,16,03,13,03,15,13,17,14,03},
{16,03,16,13,16,16,27,25,00,53,03,16,03,16,03,16,00,00,16,03},
{02,03,16,16,00,00,16,26,00,00,03,16,03,16,03,16,16,03,16,03},
{02,03,32,00,00,16,53,26,00,00,03,16,03,16,03,51,00,03,16,03},
{02,15,14,16,13,17,00,26,00,32,03,00,03,16,03,00,04,03,16,03},
{02,27,27,27,27,27,27,25,17,13,14,15,16,13,16,17,14,13,16,03},
{02,00,52,00,00,52,52,26,52,52,00,52,00,00,52,00,00,52,00,03},          
{13,17,15,13,16,15,13,13,17,03,15,13,17,13,15,17,13,14,13,17}
};


In CMM2

DIM MapData(20,15)
data 00,52,00,00,26,00,52,53,26,00,16,00,00,00,03,00,00,26,00,00
etc

then below I do

for j = 0 to 20
 for i = 0 to 15
    read MapData(i,j)
 next i
next j


Is this correct?

Thanks
RC


You're trying to read a 21 x 16 array but the data looks like it only has 20 x 15 data. Try this:
DIM MapData(19,14)
for j = 0 to 19
 for i = 0 to 14
    read MapData(i,j)
 next i
next j
Edited 2020-12-09 12:09 by toml_12953
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 528
Posted: 05:57am 09 Dec 2020
Copy link to clipboard 
Print this post

This is a common problem in Basic.
Defining an array with a size of 20 positions in C, Java, C#, etc:

int myArray[20] -> The array goes from 0 to 19.

In Basic

with "option base 0":

Dim myArray(19) -> The array goes from 0 to 19


with "option base 1":

Dim myArray(20) -> The array goes from 1 to 20
Edited 2020-12-09 15:58 by LeoNicolas
 
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 11:54am 09 Dec 2020
Copy link to clipboard 
Print this post

This is what I have and it tells me it's out out bounds.

DIM integer MAPData(19,14)

data 00,52,00,00,26,00,52,53,26,00,16,00,00,00,03,00,00,26,00,00
data 16,15,14,33,26,33,33,00,26,00,16,15,14,16,03,16,16,16,32,00
data 16,16,16,03,15,03,15,00,26,00,00,00,00,16,03,00,00,00,16,03
data 53,00,00,03,16,03,16,16,15,13,17,14,03,16,03,17,15,16,00,03
data 33,00,51,03,16,03,16,53,03,00,00,00,03,16,03,00,00,16,03,16
data 17,00,00,03,16,03,16,00,03,13,17,15,14,16,51,16,03,16,03,02
data 16,13,13,15,16,03,16,00,03,00,00,16,03,00,00,32,03,16,03,00
data 34,00,00,00,00,03,16,52,16,16,03,16,03,13,03,15,13,17,14,03
data 16,03,16,13,16,16,27,25,00,53,03,16,03,16,03,16,00,00,16,03
data 02,03,16,16,00,00,16,26,00,00,03,16,03,16,03,16,16,03,16,03
data 02,03,32,00,00,16,53,26,00,00,03,16,03,16,03,51,00,03,16,03
data 02,15,14,16,13,17,00,26,00,32,03,00,03,16,03,00,04,03,16,03
data 02,27,27,27,27,27,27,25,17,13,14,15,16,13,16,17,14,13,16,03
data 02,00,52,00,00,52,52,26,52,52,00,52,00,00,52,00,00,52,00,03
data 13,17,15,13,16,15,13,13,17,03,15,13,17,13,15,17,13,14,13,17

for j = 0 to 19
 for i = 0 to 14
   read MAPData(i,j)
next i
next j

What's wrong now?

R
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 12:04pm 09 Dec 2020
Copy link to clipboard 
Print this post

Your array indices are backwards
 
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 12:05pm 09 Dec 2020
Copy link to clipboard 
Print this post

  matherp said  Your array indices are backwards



<FACE PALM>

Thank You

RC
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025