Problems with template for my new picture-class

Hi,

I’m playing around a little bit with TADS3s Banner API. For my first try I …

… modified the standard ROOM class

modify Room
    pic = nil
  
    enteringRoom(traveler) 
    {        
      if(traveler == gPlayerChar)
        showPic();          
    }    
    
    showPic()
    {
       
      if(pic == nil)
      {
        captionWindow.deactivate();
        picWindow.deactivate();
      }     
      else
        pic.showPic();
    }
;

Then I made a new class that holds the info on the image and it’s caption (including a template for use in my room definitions)

class Picture : object
{
picFile = ‘’
caption = ‘’
showPic()
{

if(!picWindow.isActive)
{
  /* We must be careful to activate the parent window before its child */ 
  picWindow.activate();
  captionWindow.activate();
}


picWindow.updateContents('<body bgcolor=statusbg>
     <img src="pics/' + picFile + '.jpg" >');
             
captionWindow.updateContents('&lt;- ' + caption);  

}

};

Picture template ‘picFile’ ‘caption’
;

Went on to make a new room:

#charset “utf-8”
#include <de_de.h>

room_2: OutdoorRoom ‘room1’ ‘room1’
"inside room1. "

pic: Picture {
  'images/image1.png'
  'caption for image1. '
}

north = room_2    

;

Upon compiling I get an error in the room definition on the line with “pic: Picture {…” that says …

error: object definition does not match any template

Any idea what I’m doing wrong here?

Jens

Has the above line been pasted into the same file as room_2? Failing that, is the header file containing the template included in the file? Templates are not global, they must be present or included in the file to be used.

1 Like

I am indeed working with several files to separate room-code and classes and so on. And I didn’t have an include io the picture class in my room-code. TO make things a little bit easier, I now put everything into a single file, but I still end up with the same error …

“error: object definition does not match any template”

The fact that I’m using the german-lib couldn’t be a problem, could it?

Jens

#charset "utf-8"
#include <de_de.h>

room_1: OutdoorRoom 'room1' 'room1'
    "you are in room1. "
    
    pic: Picture {
      'images/room1.png'
      'caption room1. '
    }
    north = room_2  
; 

room_2: Room
  roomName = 'room2'
  desc = "you are in room2. "
  south = room_1
;


class Picture : object 
{
  picFile = ''
  caption = ''
  showPic()
  {

    if(!picWindow.isActive)
    {
      picWindow.activate();
      captionWindow.activate();
    }
  
  
    picWindow.updateContents('<body bgcolor=statusbg>
         <img src="pics/' + picFile + '.jpg" >');
                 
    captionWindow.updateContents('&lt;- ' + caption);  
  }


};

Picture template 'picFile' 'caption'
;

modify Room
    pic = nil
  
    enteringRoom(traveler) 
    {        
      if(traveler == gPlayerChar)
        showPic();          
    }    
    
    showPic()
    {
       
      if(pic == nil)
      {
  
        captionWindow.deactivate();
        picWindow.deactivate();
      }     
      else
        pic.showPic();
    }
;

modify Thing
  pic = nil

  mainExamine()
  {
    inherited();
    if(pic)
      pic.showPic();
  }
;

modify LookAction
  execAction()
  {
    inherited();
    
    local loc = gActor.getOutermostRoom();
    if(loc.pic)
      loc.showPic();
  } 
;

It shouldn’t, as template is a feature of TADS. Try moving the template to right after the include statement. All the templates I’ve found were included in a header file, but I’ve used templates outside of them before. That would make it so all the templates would be at the top of the file. Maybe they have to be declared earlier in the file than their first use. You should be able to #include a .h or .t file containing your Picture class and template. You could also just add the template to the top of every file. Your template should be working after this change as I see nothing immediately wrong with the code provided.

If it still not working after this, it could be a conflict with the German library, but we would probably need to see more code to be sure.

Thanks David, you were right! The template definition has to be at the TOP of the file (right after the includes). This way, the error “object definition does not match any template” does not appear while compiling anymore!

THANK YOU!

Jens

P.S. Got follow on problems displaying the images in the banners, but I gotta work on that for a while for myself before posting …