View unanswered posts | View active topics It is currently Tue Jul 22, 2014 4:46 pm






Reply to topic  [ 3 posts ] 
Issue with initialization of array of structures 
Author Message
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Issue with initialization of array of structures
I don't have any hard evidence to back this up, but I remember trying to define an array of structs like you are doing. I seem to remember that the following way solved the problem, but I don't have ROBOTC with me, nor do I have any example which to look back on. Perhaps you could tell me if it works.

Instead of
Code:
S_MAP_INFO  MapInfo[6]=
{
  // desktop
  { 16,   0,  16,  19, HOME_MAP_WALL},
  {  0,  19,  15,  19, HOME_MAP_EDGE},
  { 16,  19,  27,  19, HOME_MAP_WALL},
  { 27,  19,  27,  16, HOME_MAP_WALL},
  { 32,   0,  32,  16, HOME_MAP_WALL},
  { 28,  16,  31,  16, HOME_MAP_DOOR}
};


Try

Code:
S_MAP_INFO  MapInfo[6];
S_MAPINFO tempStruct = { 16,   0,  16,  19, HOME_MAP_WALL};
MapInfo[0] = tempStruct;


Or even defining the individual parts of the structure:


Code:
S_MAP_INFO  MapInfo[6];
S_MAPINFO tempStruct;
tempStruct.x1 = 16;
tempStruct.y1 = 0;
//ect.
MapInfo[0] = tempStruct;


I'm not sure why this would be the case, but I vaguely remember this working. Sorry if I'm wrong, and maybe someone else can give you a better answer.

_________________
sudo rm -rf /


Thu Jan 05, 2012 6:36 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Issue with initialization of array of structures
I tried similar thing a while back and couldn't get it to work either. So I concluded RobotC doesn't support it. In your scenario, you probably want to enter your initializers into a text file and write RobotC code to open the file and read the info from it. It's more versatile anyway because you can reuse your program with another room configuration without changing code.


Thu Jan 05, 2012 6:49 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Issue with initialization of array of structures
BTW, I did not look through your code carefully last time. But when looking it again, I found one issue with the following function:
Code:
void  Map_Fill(ubyte x1, ubyte y1, ubyte x2, ubyte y2, ubyte type)
{
  ubyte x;
  ubyte y;
 
  if(x1>x2) {x=x1; x1=x2; x2=x;}
  if(y1>y2) {y=y1; y1=y2; y2=y;}
  for(x=x1; x<=x2; x++)
    for(y=y1; y<=y2; y++)
      home.cell[x][y] = type;
}

You declared the type parameter a "ubyte", shouldn't it be "int"? That will truncate the upper byte where the actual type info is located.


Fri Jan 06, 2012 3:48 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.