Author Topic: Macro errors  (Read 1899 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Macro errors
« on: October 04, 2011, 03:21:21 am »
Trying to include PeriodDesc.c across all the rooms in my area so I don't have to copypaste identical code 50 times.  Is giving me the errors "Invalid macro name" and "Illegal macro symbol" at line 85 of the room file.  Suspect something foolishly naive that I'm doing wrong or missing rather than an actual problem.

file: /domains/guri/room/03,28,0_wallbase.c
Code: [Select]
#include <lib.h>
#include <daemons.h>
#include <terrain_types.h>
#include ROOMS_H

inherit LIB_ROOM;
inherit "/domains/guri/PeriodDesc.c";

string DescLong(){
string desc = "";
desc += PeriodDesc( GetTerrainTypeName() );
desc +=
//---1----2----3----4----5----6----7----8----9----A----B----C
"Description placeholder.";
return desc;
}

static void create(){
room::create();
SetClimate( "temperate" );
SetTerrainType( T_OUTDOORS );
SetAmbientLight( 25 );
SetShort( "the base of the wall" );
SetCoordinates( "03,28,0" );
SetLong( (: DescLong :) );
SetTown( "Guri" );
SetEnters( ([
"woods" : "/domains/guri/room/07,26,0_woods"
]) );
}

void init(){ ::init(); }

Code: [Select]
#include <daemons.h>

string PeriodDesc( string *terrain ){
int SOP;
string timeofday, season, groundcover;

if( sizeof( terrain ) == 0 ){ terrain = ({ "outdoors" }); }
SOP = SEASONS_D->GetSOP();
season = SEASONS_D->GetCurrentSeason( time() );
timeofday = SEASONS_D->GetTimeOfDay();
write( sprintf( "Your terrain type is %O.", terrain ) ); // test
switch( season ){
case "midwinter":
case "late-winter":    groundcover = "drifts of snow"; break;
case "nascent spring":
case "early-spring":   groundcover = "spotty patches of melting snow"; break;
case "midspring":
case "late-spring":    groundcover = "blooming flowers"; break;
case "nascent summer":
case "early-summer":
case "midsummer":
case "late-summer":    groundcover = ""; break;
case "nascent autumn":
case "early-autumn":
case "midautumn":      groundcover = "dry leaves on the ground"; break;
case "late-autumn":
case "nascent winter": groundcover = "frosty ground"; break;
case "early-winter":   groundcover = "snow"; break;
default:               groundcover = ""; break;
}
if( member_array( "windowed", terrain ) > -1 ){
switch( timeofday ){
case "day":
switch( SOP ){  // put in a check for if that wall has a window
case 000..089: return "The window glows faintly with the new morning light.  ";
case 090..134: return "The morning sun shines through the window.  ";
case 135..224: return "The bright sun shines through the window in the ceiling.  ";
case 225..270: return "The setting sun shines through the window.  ";
case 271..359: return "The light outside the window fades.  ";
default:       return "This text shouldn't appear.  ";
}
default: return "";
}
}else if(
member_array( "indoors", terrain ) > -1 ||
member_array( "space", terrain ) > -1 ||
member_array( "plasma", terrain ) > -1 ||
member_array( "underground", terrain ) > -1 ||
member_array( "magma", terrain ) > -1 ||
member_array( "planar", terrain ) > -1 ||
member_array( "custom", terrain ) > -1
){
return "";
}else if( member_array( "forest", terrain ) > -1 ){
return "Sunlight filters through the foliage.";
//return "Sunlight filters between the bare branches.";  etc
}else{
switch( timeofday ){
case "dawn":
return sprintf(
"The rosy fingers of the dawn color the eastern sky%s.  ",
groundcover != "" ? ", and paint the " + groundcover + " in shades of lavender" : ""
);
case "day":
switch( SOP ){
case 090..100:
return sprintf(
"The pearly rays of early-morning sun cast long shadows westwards%s.  ",
groundcover != "" ? " over the " + groundcover : ""
);
case 101..174: return "The morning " + season + " sun shines in the sky.  ";
case 175..185: return "The bright " + season + " sun is directly overhead.  ";
case 186..259: return "The afternoon " + season + " sun shines in the sky.  ";
case 260..270:
return sprintf(
"The golden rays of the sun cast long shadows eastwards%s as it sets.  ",
groundcover != "" ? " over the " + groundcover : ""
);
default:       return "Time of day is " + timeofday + " and SOP is " + SOP + "; this text shouldn't appear.  ";
}
case "dusk":
return "The soft ember hues of the " + season + " sunset fade in the sky to the west.  ";
case "night":
return "Myriad pinpoints of stars scatter across the " + season + " sky like diamonds.  ";
default:
return "";
}
}
return "Something is seriously wrong; this text should never appear from the function PeriodDesc().  ";
}

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: Macro errors
« Reply #1 on: October 04, 2011, 04:11:36 am »
Note of potential interest:  if it's not a virtual room, don't use a coordinate triplet at the start of a filename!

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: Macro errors
« Reply #2 on: October 04, 2011, 10:57:15 am »
You should always include the lib and driver versions, it helps a lot in finding the problem.

That said, the culprit appears to me to be the "SOP" variable in PeriodDesc.c. Since your room inherits this file, line 79 of PeriodDesc.c + the 6 lines or so above the inherit line in your room == line 85, which is this line:
Code: [Select]
default:       return "Time of day is " + timeofday + " and SOP is " + SOP + "; this text shouldn't appear.  ";
Of course, I could be completely wrong and it could be an error in one of your header files.

Assuming it is your PeriodDesc.c file, I looked at DS 3.4 and there is no "SEASONS_D->GetSOP" function so I can only assume this is something you've added. The error handler is probably calling it a macro because it's in uppercase. The above line is only being called during the day, when switch( SOP ) goes to the default option. So check out your GetSOP function and make sure it's working, and renaming SOP to sop may help the error handler give better information.

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: Macro errors
« Reply #3 on: October 10, 2011, 06:09:19 pm »
Turns out the problem was the file names.  Had tried making them e.g. 03280, but as one of the things tries to define a variable to the room's name, using a number wasn't flying either.  Changing to rm03280 fixed things.