Author Topic: Syntax error  (Read 4140 times)

vakuta

  • Guest
Syntax error
« on: September 19, 2006, 12:23:36 pm »

Hi.  Tell me, this code for my Ja Lounge room is almost perfect, but apparently there is a syntax error on line 12.  Can you find it?  I don't see one.





#include <lib.h>

#include "./customdefs.h"



inherit LIB_ROOM;



static void create() {

    room::create();

    SetClimate("indoors");

    SetAmbientLight("10");

    SetShort("Ja Lounge");

    SetLong("This cozy little lounge is dimly lit by tall, white candles.  A fire crackles in the fireplace on the back wall, giving the place a cozy sort of feel.  The grate in front of the fire has some very interesting patterns on it.  Over on the right wall is a bar serving some fine drinks, and on the left wall are some bookcases.  A few armchairs are scattered around here and there.");

SetItems( ([ ({"fireplace"}) : "A fire burns in the fireplace at the back of the room, casting a cozy light over the lounge.",  ({"bookcases"}) : "The bookcases are lined with books, apparently here for the patrons' pleasure.",  ({"grate"}) : "The grate has some interesting designs on it.  Maybe you should take a closer look.",  ({"designs"}) : "They seem to have a symbolic meaning.",  ({"patterns")} : "The patterns on the fireplace grate seem to have a symbolic meaning.",  ({"books"}) : "The titles are very interesting.  One is particularly interesting, entitled 'The Legacy of the Wyrm'.",  ({"candles"}) : "The tall, white, candles burn here and there around the room, providing the perfect lighting along with the fire.",  ({"armchairs"}) : "The armchairs look very comfortable.",  ({"chairs"}) : "The armchairs look very comfortable.",  

      ]) );

    SetExits( ([

        "south" : MY_DIR "/workroom",

      ]) );

}



void init(){

    ::init();

}



 





I can't find it in any way, not in the raw code, not through the mud's cd/ls/cat commands, no way.


Offline Aransus

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Syntax error
« Reply #1 on: September 19, 2006, 12:33:20 pm »
The problem: You are using arrays as keys to your SetItems() mapping, when you should be using strings.



The fix:



({ "fireplace" }) ---should be---> "fireplace"

({ "bookcases" }) ---should be---> "bookcases"

etc...



Hope that helps!



Edit: Just figured I'd add in a full, syntactically correct SetItems() bit, for the sake of completeness.



SetItems( ([

  "fireplace" : "There's a fireplace here.",

  "bookcases" : "There are bookcases here.",

// Side note: The comma at the end of the above line is optional

]) );



I suggest putting each item on a new line, for a number of reasons. It enhances code readability, makes it easier to edit/add/delete items, and simplifies tracking down pesky little errors.



-- Aransus

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Syntax error
« Reply #2 on: September 19, 2006, 12:42:31 pm »

Actually, arrays are legal there, they shouldn't cause

a problem, other than perhaps an aesthetic one ;)



The cause of the error is that you transposed a bracket

and a parenthesis. If you switch them, you'll have it fixed.



The way to avoid this confusion in the future is by breaking up

your code into separate lines. The big hangup here is that you have

a biglargehuge line, and an error on it, so you have to poke,

character by character, to find where you made the error.



I suggest you break up that SetItems line into one line

per item, and then try to update.



You'll then be given a line number for the syntax error that

you can actually use to fix the problem.



Oh and following Aransus's advice should work too,

since it'll eliminate the transposed characters.


Offline Aransus

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Syntax error
« Reply #3 on: September 19, 2006, 12:57:20 pm »

Doh, you're right, that was dumb  :P. The array functionality is actually damn useful, because it lets you map one description to many item names. Ah well, the brain can't work all the time :).



Anyway, I noticed something else that's going to give you trouble when you try to load this room, Zaroth. On line 9, you have SetAmbientLight("10"). You're passing a string to SetAmbientLight(), instead of an integer. The file will still update successfully, but you'll get crazy errors when you try to go to the room. Change it to SetAmbientLight(10) (without the quotes around the 10), and you should be fine.



Sorry to spin you in circles with bad advice the first time around!



-- Aransus


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Syntax error
« Reply #4 on: September 19, 2006, 01:00:58 pm »

Aransus,

Hey your advice would have fixed his problem, so it works out!



Also, nice catch on the SetLight. I missed that :)



vakuta

  • Guest
Syntax error
« Reply #5 on: September 19, 2006, 03:32:14 pm »
I copied the SetItems() code from a file where it worked, Aransus.  :P

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Syntax error
« Reply #6 on: September 19, 2006, 03:40:58 pm »
What file?

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Syntax error
« Reply #7 on: September 19, 2006, 04:10:53 pm »
Yeah, what file? Your spacing may be off, you may be missing a " or a ( or a {

vakuta

  • Guest
Syntax error
« Reply #8 on: September 19, 2006, 06:06:55 pm »
The file I copied the function from was /domains/default/room/wiz_hall.c

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Syntax error
« Reply #9 on: September 19, 2006, 07:07:34 pm »

I'm confused.



That file has only one SetItem in it, and it is correctly written.



Your statement implied that your file should have worked, because

the file you copied from worked.



I think you must have made an error during the copying process,

because the broken bracket syntax is not in the file

you mentioned.



Am I misunderstanding what you meant?