Game authors and players, please read this thread!

Author Topic: Problem setting Height in dialog_options_get_dimensions [Solved]  (Read 323 times)  Share 

I hope this is a simple scripting problem.
I am creating a custom dialog and no matter what I try the Height of the options box is rendered at what seems to be an arbitary value.
The code is picking up the right dialog, and calculating the number of options and the Height correctly, but this Height and corresponding Y value are not being used.
Here is the code:

Code: Adventure Game Studio
  1.  
  2. function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  3.   int ocount;
  4.   int oindex;
  5.   ocount=0;
  6.   oindex=1;
  7.  
  8.   info.Y = 470;
  9.   info.Height = 0;
  10.  
  11.  
  12.   while (oindex <= info.DialogToRender.OptionCount) {
  13.     if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
  14.       info.Y -=8;
  15.       info.Height +=8;
  16.       ocount++;
  17.     }
  18.     oindex++;
  19.   }
  20.   vDialogNo=info.DialogToRender.ID;
  21.   vOptionCount=ocount;
  22.   vDialogHeight=info.Height;
  23.  
  24.   info.X = 40;
  25.  
  26.   info.Width = 560;
  27.  
  28. }
  29.  
  30.  

Any help or advice appreciated.
« Last Edit: 02 Sep 2012, 20:14 by Hernald »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Problem setting Height in dialog_options_get_dimensions
« Reply #1 on: 02 Sep 2012, 10:50 »
A shot in the dark:

Code: Adventure Game Studio
  1. function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  2.   int ocount, oindex = 1;
  3.  
  4.   while (oindex <= info.DialogToRender.OptionCount) {
  5.     if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) ocount++;
  6.     oindex++;
  7.   }
  8.  
  9.   vDialogNo = info.DialogToRender.ID;
  10.   vOptionCount = ocount;
  11.   vDialogHeight = ocount * 8;
  12.  
  13.   info.X = 40;
  14.   info.Y = 470 - ocount * 8;
  15.   info.Height = ocount * 8;
  16.   info.Width = 560;
  17. }
It shouldn't make any difference though, and I can't really see what's wrong with the original code. The only thing that's different is I'm not setting info's fields multiple times.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

cat

  • Mittens Vassal
  • AGS Baker
  • cat worked on a game that was nominated for an AGS Award!
Re: Problem setting Height in dialog_options_get_dimensions
« Reply #2 on: 02 Sep 2012, 11:47 »
Are you sure you handle it correctly in dialog_options_render?

Re: Problem setting Height in dialog_options_get_dimensions
« Reply #3 on: 02 Sep 2012, 16:14 »
Khris: Yes, I had tried it that way earlier; anything other than a simple uncalculated integer seems to come out wrong;
cat: The dialog_options_render is taken straight from the manual with just the background colour and font changed. Okay I'll post it in case I've messed something up:
Code: Adventure Game Studio
  1.  
  2. function dialog_options_render(DialogOptionsRenderingInfo *info)
  3. {
  4.   // Clear the area pale green
  5.   info.Surface.Clear(36269);
  6.   int i = 1,  ypos = 0;
  7.   // Render all the options that are enabled
  8.   while (i <= info.DialogToRender.OptionCount)
  9.   {
  10.     if (info.DialogToRender.GetOptionState(i) == eOptionOn)
  11.     {
  12.       if (info.ActiveOptionID == i) info.Surface.DrawingColor = 13;
  13.       else info.Surface.DrawingColor = 4;
  14.       info.Surface.DrawStringWrapped(5, ypos, info.Width - 10,
  15.                          eFontNormal, eAlignLeft, info.DialogToRender.GetOptionText(i));
  16.       ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontNormal, info.Width - 10);
  17.     }
  18.     i++;
  19.   }
  20. }
  21.  

Thank you both for coming back to me, but I'm afraid I'm still in the dark...

Re: Problem setting Height in dialog_options_get_dimensions
« Reply #4 on: 02 Sep 2012, 20:13 »
cat: You were right! The problem was caused by me not measuring the height of the rows of text in dialog_options_render.
I've simplified that code a bit and given the font more space and now it is working fine!
Thank you both for your input.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Just to clarify, the GUI wasn't tall enough because you always used a height of 8 pixels for an option, even if it spanned multiple lines, correct?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Eight pixels was nowhere near enough for one line let alone multiple lines.
I've  copied up the GetTextHeight function from dialog_options_render to dialog_options_get_dimensions and now it works perfecly:
Code: Adventure Game Studio
  1.  
  2. function dialog_options_get_dimensions (DialogOptionsRenderingInfo *info){
  3.   int ocount=0, oindex=1;
  4.  
  5.  
  6.   info.X = 40;
  7.   info.Width = 560;
  8.   vDialogHeight=0;
  9.  
  10.   while (oindex <= info.DialogToRender.OptionCount) {
  11.     if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
  12.       vDialogHeight+=GetTextHeight(info.DialogToRender.GetOptionText(oindex), eFontSpeech, info.Width - 10);
  13.       ocount++;
  14.     }
  15.     oindex++;
  16.   }
  17.  
  18.   vOptionCount=ocount;
  19.    
  20.   info.Y = 470 - vDialogHeight;
  21.  
  22.   info.Height = vDialogHeight;
  23.  
  24.   vDialogNo=info.DialogToRender.ID;
  25.  
  26. }
  27.  
It was a basic programming issue as I'd hoped; I guess I'd been at it for a while and needed to give my brain a rest, and a fresh perspective.