Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Gold Dragon on Sun 11/05/2008 05:50:29

Title: How do I solve? Runtime error: unexpected eof at line -10??
Post by: Gold Dragon on Sun 11/05/2008 05:50:29
Acutually the Full error is Runtime error: unexpected eof .... File: SpriteFont.asc ... Line -10 !?!?!?

First off I would like to abundantly thank anyone who attempts to solve my two problems. Two? Yes two, I will get to that in a second here.

Ok once more I'm trying to Customize SSH's SpriteFont to do more. I know you guys might start getting tired of me attempting this, but I refuse to give up

The Goal is to create this..

(http://i235.photobucket.com/albums/ee80/Danor78/AGS/TestingWindow.png)

..Dynamically with these sprite tiles.

Custom Gui Text box Tiles
(http://i235.photobucket.com/albums/ee80/Danor78/AGS/DkWindowTiles.png)

Custom sprite Letter Tiles
(http://i235.photobucket.com/albums/ee80/Danor78/AGS/DragonKnightLetters.png)

ok on to the two problems....

SSH's orginal code can be found here. http://ssh.me.uk/modules/SpriteFont.zip

(Jump down to the bottom of the post to see my explanation and requests)

My modification to SSH's SpriteFont struct in SpriteFont.ash is this....

struct SpriteFont {
  // Public
  import function SetFontSprite(char c, int spr);
  import function SetGuiSprite(int Ctr, int spr);     //****** My Gui Sprite Setting Function*********
  import function FontSpritesFromView(int v, char firstchar, char numsprites=-1);
  import function GuiSpritesFromView(int v);      //******* My import Gui sprites function*********
  import function FontSpritesFromChar(Character *c, char firstchar=-1, char numsprites=-1);
  import function SetFontSpriteFromFile(char c,  String filename);
  import function FontSpritesFromFiles(String fileroot, char firstchar, char numsprites);
  import function GetSpriteTextRawWidth(String t);
  import function GetSpriteTextRawHeight(String t);
  import function TextOnDrawingSurface(
#ifver 3.0
        DrawingSurface *ds,
#endif
        int x, int y, String t, int transparent=0, int angle=0);
  import function TextOnBackground(int x, int y, String t, int transparent=0, int angle=0,  bool Dsp=true);
  import DynamicSprite *TextOnSprite(String t);
  import Overlay *TextOnOverlay(int x, int y, String t, bool transparent=0);
  import Overlay *RenderDisplay(int x, int y, String text );      // *******  monkey_05_06's  RenderDisplay  *******
                                                                                                                         // [[THANK YOU!!]]
  import function display(int x,  int y, String txt);  // My Display function
  int CharSpacing;
  int LineSpacing;
   
  // Private
  protected import function GetSpriteCharRawWidth(char c);
  protected int sn[MAX_CHAR_VALUE];
  protected int GuiSpriteNumber[9];    // *********My Gui Sprite holder Array*********
  protected int Max_Txt_Pxl_Width;   // ****My Maxium width of Desired Gui Text Box **
  protected DynamicSprite *ds[MAX_CHAR_VALUE];
};


My function definitions in SpriteFont.asc are......


// *****************  My Gui Sprite Setting Function ************************
function SpriteFont::SetGuiSprite(int Ctr, int spr){
  this.GuiSpriteNumber[Ctr]=spr;  // Put the Sprite Number in Gui Text Box Ctr

}

// Modified from......

function SpriteFont::SetFontSprite(char c, int spr) {
  this.sn[c]=spr;
  this.ds[c]=null;
  int height=Game.SpriteHeight[spr];
  if (height>this.LineSpacing) this.LineSpacing=height; // find tallest char
}
.
.
.
// ************** My import Gui sprites function ***************************
//   Adapted from SpriteFont's FontSpritesFromView

function SpriteFont::GuiSpritesFromView(int v){
  int i=0;
  int loop=0;
  int frame=0;
  while (i!=8) {
    ViewFrame *vf=Game.GetViewFrame(v, loop, frame);
    this.SetGuiSprite(i, vf.Graphic);
    i++;
    frame++;
    if (frame >= Game.GetFrameCountForLoop(v, loop)) {
loop++;
frame=0;
}
if (loop >= Game.GetLoopCountForView(v)) {
Display("ERROR: SpriteFont.GuiSpritesFromView: not enough sprites in view");
QuitGame(0);
}
}


function SpriteFont::FontSpritesFromView(int v, char firstchar, char numsprites) {
  int i=0;
  int loop=0;
  int frame=0;
  while (i!=numsprites) {
    ViewFrame *vf=Game.GetViewFrame(v, loop, frame);
    this.SetFontSprite(firstchar+i, vf.Graphic);
    i++;
    frame++;
    if (frame >= Game.GetFrameCountForLoop(v, loop)) {
loop++;
frame=0;
}
if (loop >= Game.GetLoopCountForView(v)) {
  if (numsprites<0) return; // -1 just reads all sprites in view
  else {
Display("ERROR: SpriteFont.FontSpritesFromView: not enough sprites in view: specified %d, actually %d", numsprites, i);
QuitGame(0);
  }
}
}
}
.
.
.
// *****************************  monkey_05_06's  RenderDisplay **************************************
// It draws a nice box and boarder around the custom text, but that box and text are still stuck to the screen  :(
//                  Can anyone show me or mokey can you modify so this disapears like a regular Display() function?

Overlay *SpriteFont::RenderDisplay(int x, int y, String text) {
  if ((text == null) || (text == "")) return null; // invalid text parameter, abort
  int width = this.GetSpriteTextRawWidth(text) + this.LineSpacing + 4; // create the box big enough to fit the text, with 1/2 line-spacing padding, and a 2 pixel black border
  int height = this.GetSpriteTextRawHeight(text) + this.LineSpacing + 4;
  DynamicSprite *sprite = DynamicSprite.Create(width, height); // the sprite we will render our textbox onto
  DynamicSprite *textSprite = this.TextOnSprite(text); // here we grab the sprite-text into a sprite so we can draw it into our textbox
  DrawingSurface *surface = sprite.GetDrawingSurface(); // finally open up the sprite to begin drawing
  surface.DrawingColor = 31; // white for the background
  surface.DrawRectangle(0, 0, sprite.Width, sprite.Height); // fill the entire sprite with white, everything else will go on top
  surface.DrawingColor = 0; // black for the border
  surface.DrawLine(0, 0, 0, sprite.Height, 2); // draw the border at 2px wide
  surface.DrawLine(0, 0, sprite.Width, 0, 2);
  surface.DrawLine(sprite.Width, 0, sprite.Width, sprite.Height, 2);
  surface.DrawLine(0, sprite.Height, sprite.Width, sprite.Height, 2);
  surface.DrawImage(2 + (this.LineSpacing / 2), 2 + (this.LineSpacing / 2), textSprite.Graphic); // draw our text
  surface.Release(); // release the sprite so we can create the overlay
  textSprite.Delete(); // delete this sprite, we don't need it any more
  if (x == -1) x = (System.ViewportWidth - sprite.Width) / 2; // default x to center-screen
  if (y == -1) y = (System.ViewportHeight - sprite.Height) / 2; // default y to center-screen
  if (x < 0) x = 0; // if the x value is negative, set it back to 0
  if (y < 0) y = 0; // same for y value
  Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
  sprite.Delete(); // delete our temporary sprite
  return displayOverlay; // return the overlay so we can use it (move it around, remove it, etc.) (also if we don't it will be deleted! ;))
}
.
.
.
.
// ******************  My New attempt at a Text box Gui with custom Sprite Gui Text Tiles  *************************
function SpriteFont::display(int x,  int y, String Txt){

  int GuiBoxlength=0;
  int GuiBoxheight=0;
  int MiddleLoop=0; // int for how many Top Middle tiles there are?
  this.Max_Txt_Pxl_Width=600;  // Set Max text Length wanted. This will be setted by a function in the future
   
  if ((Txt == null) || (Txt == "")) return; // invalid text parameter, abort
  if ((x == 0) && (y == 0)){       // Set Default if no Parm is passed
    x=127;
    y=121;
  }

  int Txtwidth = this.GetSpriteTextRawWidth(Txt); // Get how long the text Graphics will be.
  int Lines = (Txtwidth / this.Max_Txt_Pxl_Width); // Find out how many lines will be in the Txt Box
   
 
  if (Lines == 0){   // if there is only 1 line. Get Box Length and height for sprite.
    // Get Sprite With of Top Left Gui Sprite
    int TopM=Game.SpriteWidth[this.GuiSpriteNumber[1]]; // Get Width of Top Middle custom Tile
 
    while(GuiBoxlength<Txtwidth){    // Get full Width of the Box's top middle
      GuiBoxlength+=TopM;
      MiddleLoop++;  // adding how many top middle sprites there are
    }
 
    GuiBoxlength+=Game.SpriteWidth[this.GuiSpriteNumber[0]] * 2; // Add the length of the two Corner end pieces of the top part of the box for Full Width of the Gui Text Box
    GuiBoxheight=(Game.SpriteHeight[this.GuiSpriteNumber[0]] * 2) + (Game.SpriteHeight[this.GuiSpriteNumber[3]]);// Get height by X2 top corner pieces and middle graphic for Full Height of Gui Text Box
  }

  else{
    int TopM=Game.SpriteWidth[this.GuiSpriteNumber[1]];  // Get Width of Top Middle custom Tile
    while(GuiBoxlength<this.Max_Txt_Pxl_Width){    // Get how many Top Middle Tiles there are. This has to be done due to the fact
                                                   // that custom Gui tile sizes are difrent lengths
      GuiBoxlength=GuiBoxlength + TopM;
      MiddleLoop++;  // adding how many top middle sprites there are to match Max_Txt_Pxl_Width
    }
    GuiBoxlength+=(Game.SpriteWidth[this.GuiSpriteNumber[0]] * 2); // Add the length of the two end pieces of the top part of the box
    GuiBoxheight=(Game.SpriteHeight[this.GuiSpriteNumber[0]] * 2) + (Game.SpriteHeight[this.GuiSpriteNumber[3]] * Lines);// Get height by X2 edge pieces pluss height of side middle tile X how many lines their are
 
  }

  //DynamicSprite *clr=DynamicSprite.CreateFromBackground(GetBackgroundFrame(), x, y, GuiBoxlength, GuiBoxheight); //create the erase image
 
  DynamicSprite *sprite=DynamicSprite.Create(GuiBoxlength, GuiBoxheight); // create a sprite as big as the text box needs to be.
  DrawingSurface *TxtBox=sprite.GetDrawingSurface(); // Make a drawing surface to Draw the tiles on too
 
 
  // Draw The Txt box
  int spriteX=x;  //create another x and y that we can manipulate to draw onto our txt box
  int spriteY=y;
  TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[0]);  // Draw Top Left Tile Onto the sprite
  spriteX+=Game.SpriteWidth[this.GuiSpriteNumber[0]]; // advance spriteX forward
 
  while(MiddleLoop>0){  //Put the Top Middle Tiles in
    TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[1]);
    spriteX+=Game.SpriteWidth[this.GuiSpriteNumber[1]];
    MiddleLoop--;
  }
 
  TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[2]); // Draw top Right Tile
 
  // I stopped here to just to see if the top part of the Sprite would be drawn Correctly
 
  TxtBox.Release();  // Update Memory
 
   
  Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
  sprite.Delete(); // delete our temporary sprite
  //return displayOverlay; // return the overlay so we can use it (move it around, remove it, etc.) (also if we don't it will be deleted! ;))
  Wait(400);
  //clear.Release();
  displayOverlay.Remove();

}




Ok after I've added my code I get that weird Error... Runtime error: unexpected eof .... File: SpriteFont.asc ... Line -10 !?!?!?

So its something in my code but what?!?

OK These are my problems

1) How do I get rid of this Error? when I Rem my code out everything runs fine. But as far as I can tell every {} and () lines up so whats the deal and why would it do this at line -10???

2)Can anyone look over my code and make sure that it would actually work?

3)Help me use monkey_05_06's properly or how to modify it so it disapears after clicking or pressing a Key like a Display() function. Right now its glued to the screen. I would like to fix this so I can use it as a back up if my custom tile Gui text box is not doable.


Whats that? I said that there were only two problems and I listed three??  *shrugs* Sorry Thought of the third while writing this

But in all seriousness and kidding aside can anyone... ANYONE I TELL YOU help me with my problems. I would be eternally thankful and would make my game really awsome.

Also SSH if your reading this. Maybe you can use my code to give you a head start on making your SpriteFont even better? Thanks for makeing such a great script Module.
Title: Re: How do I solve? Runtime error: unexpected eof at line -10??
Post by: monkey0506 on Sun 11/05/2008 06:22:22
Generally EOF at line -10 means you're missing a closing bracket, but you've said they all line up properly. You may try commenting out your entire script and then uncommenting one function at a time until you find the offending function.

As for the code I wrote not removing itself, perhaps you could try this instead:

void noloopcheck SpriteFont::RenderDisplay(int x, int y, String text) { // don't put noloopcheck in the import, just the definition
  if ((text == null) || (text == "")) return null; // invalid text parameter, abort
  int width = this.GetSpriteTextRawWidth(text) + this.LineSpacing + 4; // create the box big enough to fit the text, with 1/2 line-spacing padding, and a 2 pixel black border
  int height = this.GetSpriteTextRawHeight(text) + this.LineSpacing + 4;
  DynamicSprite *sprite = DynamicSprite.Create(width, height); // the sprite we will render our textbox onto
  DynamicSprite *textSprite = this.TextOnSprite(text); // here we grab the sprite-text into a sprite so we can draw it into our textbox
  DrawingSurface *surface = sprite.GetDrawingSurface(); // finally open up the sprite to begin drawing
  surface.DrawingColor = 31; // white for the background
  surface.DrawRectangle(0, 0, sprite.Width, sprite.Height); // fill the entire sprite with white, everything else will go on top
  surface.DrawingColor = 0; // black for the border
  surface.DrawLine(0, 0, 0, sprite.Height, 2); // draw the border at 2px wide
  surface.DrawLine(0, 0, sprite.Width, 0, 2);
  surface.DrawLine(sprite.Width, 0, sprite.Width, sprite.Height, 2);
  surface.DrawLine(0, sprite.Height, sprite.Width, sprite.Height, 2);
  surface.DrawImage(2 + (this.LineSpacing / 2), 2 + (this.LineSpacing / 2), textSprite.Graphic); // draw our text
  surface.Release(); // release the sprite so we can create the overlay
  textSprite.Delete(); // delete this sprite, we don't need it any more
  if (x == -1) x = (System.ViewportWidth - sprite.Width) / 2; // default x to center-screen
  if (y == -1) y = (System.ViewportHeight - sprite.Height) / 2; // default y to center-screen
  if (x < 0) x = 0; // if the x value is negative, set it back to 0
  if (y < 0) y = 0; // same for y value
  Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
  sprite.Delete(); // delete our temporary sprite
  while (!WaitMouseKey(1)) {} // returns 0 if the time has elapsed, 1 if a mouse button or key was pressed
  displayOverlay.Remove();
}


That would work more like a regular Display statement. Making it obey the display-skipping option gets more complicated, especially if set to mouse-only mode.
Title: Re: How do I solve? Runtime error: unexpected eof at line -10??
Post by: Gold Dragon on Sun 11/05/2008 07:03:28
THANKS MONKEY!!

Now I have my back up function.. now on to finding that missing bracket  *sigh*

When I rem out the function SpriteFont::display(int x,  int y, String Txt) Everything runs fine.. so its in there?!? But where???

*digs out magnifying glass*
"Mr. Lumpy.. the game is afoot!!"

EDIT: Found it.. there were to instances of missing ')' and the orginal post above has been updated... Thanks again monkey!