ERROR: Game start failure?

Started by monkey0506, Tue 30/08/2005 16:59:12

Previous topic - Next topic

monkey0506

Okay, I've recently encountered an error which seemingly causes the game to fail to start.  Not that I get an error message, the game doesn't even crash.  It just fails to start.  I have stared at a blank screen for more than 5 minutes, and I finally just gave up.

Okay, here's the basic gist of the code:

Code: ags
// SM HEADER
struct ScrollingDialog {
  import static String GetText(int dialog, int option);
  };

// SM SCRIPT

String ScrollingDialog_RETRIEVETEXT;

static String ScrollingDialog::GetText(int dialog, int option) {
  if ((dialog < 0) || (dialog >= ScrollingDialog_MAX_DLGS))
    AbortGame("Invalid parameter 'dialog' to function 'ScrollingDialog::GetText'.  Range from 0 to %d.  Value %d.", ScrollingDialog_MAX_DLGS - 1, dialog);
  if ((option < 0) || (option >= ScrollingDialog_MAX_OPTS))
    AbortGame("Invalid parameter 'option' to function 'ScrollingDialog::GetText'.  Range from 0 to %d.  Value %d.", ScrollingDialog_MAX_OPTS - 1, option);
  String Text = "";
  readonly int strstart = option * 200;
  int i = strstart;
  while (i < strstart + 200) {
    Text = String.Format("%s%c", Text, Dialog[dialog].Text[i]);
    i++;
    }
  ScrollingDialog_RETRIEVETEXT = Text;
  return ScrollingDialog_RETRIEVETEXT;
  }

void InitializeDialogs() {
  SetDialogText(0, 0, "My name's Guybrush Threepwood!  Prepare to die!");
  
  int dialog = 0;
  while (dialog < ScrollingDialog_MAX_DLGS) {
    int option = 0;
    while (option < ScrollingDialog_MAX_OPTS) {
      if (option < ScrollingDialog_NUM_LBLS) {
        Dialog[dialog].Width[option] = GetTextWidth(ScrollingDialog.GetText(dialog, option), ScrollingDialog_DLG_FONT);
        if (Dialog[dialog].Width[option] >= gDialog.Width) {
          string output;
          string tail;
          StrCutByWidth(ScrollingDialog.GetText(dialog, option), gDialog.Width, ScrollingDialog_DLG_FONT, output, tail);
          Dialog[dialog].SetText(option, output);
          Dialog[dialog].SetHalfText(option, tail);
          Dialog[dialog].Width[option] = GetTextWidth(ScrollingDialog.GetText(dialog, option), ScrollingDialog_DLG_FONT);
          Dialog[dialog].HalfWidth[option] = GetTextWidth(ScrollingDialog.GetHalfText(dialog, option), ScrollingDialog_DLG_FONT);
          }
        }
      option++;
      }
    dialog++;
    }
  }


Well I've changed it up a bit to try and make it more like the actual code I used (I've already found a way to fix the problem) when I got this problem, without clogging it down with excessive stuff.  If you want to see the complete code just ask and I'll post it (although it's 270 lines w/o the header).  I fixed the problem by just putting "this.Width[option] = GetTextWidth(text, ScrollingDialog_DLG_FONT);" into the SetText function...

Thanks for any info.

[EDIT:]  Well I've found that my ScrollingDialog::Run(int dialog) function also creates the same error...without calling GetTextWidth.  I'll try to search around and let you know if I find anything...  And just for those who have been keeping an eye out, the ScrollingDialog SM is nearing completion.  As soon as I can get these bugs worked out.  Then all I have to do is write the scrolling functions (which is easy to do with the way I have it set up now).  So once again thanks for any help with this problem!

[EDIT:]  A simple bit of re-scripting seems to have solved the error with the Run function.  One fore-warning to those who plan to use the ScrollingDialog SM though...it's currently taking me about 1 minute to load the game if I start it in a dialog... And thinking back on it, I lied about only having to write the scrolling functions.  I also have to put a cursor in so I can tell it to run the appropriate interaction when the user clicks, I have to make the highlight function to highlight the selected dialog, and then I have to add the scrolling functions...well, at least I've finally made some progress!

Pumaman

Sorry, I'm a bit confused now ... can you clarify exactly what does cause the problem?

monkey0506

#2
I have no idea! ;D

Well seriously I don't know why it happened, but the code has been revised a lot since then and I don't get the problem any more.  Probably just a bit of bad code on my part...

[EDIT:]  Okay...I think I have a problem...I think I exaggerated on the time I waited for the game to start, and I think that I have another function that's doing the same thing.

I have a fairly small loop (as far as the game should be concerned) that is taking forever to run, and I was just wondering if there is any explanation as to why.

Code: ags
#define ScrollingDialog_MAX_STRS 15000  /* ScrollingDialog_MAX_OPTS * ScrollingDialog_MAX_DLGS */

String Text[ScrollingDialog_MAX_STRS];
String HalfText[ScrollingDialog_MAX_STRS];
String RetrieveOptionText;

void ClearStrings() {
  int i = 0;
  while (i < ScrollingDialog_MAX_STRS) {
    Text[i] = "";
    HalfText[i] = "";
    i++;
    }
  RetrieveOptionText = "";
  }

function game_start() {
  ClearStrings();
  }


That is my code (in a SM script file), and the only thing called from game_start at the moment (in all scripts) is the ClearStrings function.  For some reason...it takes about 1 - 2 minutes to run this function...  I don't see any reason why 15000 loops should be taking so long to run when I have created an error caused by 150000 loops being run in under 30 seconds before...

I hope this may shed some light as to an answer to my dilemma...please?  (Before I was using a large char array to store the text, but a String to retrieve it...perhaps this is a problem with the String type???)

Pumaman

This code is creating 30000 Strings, which involves 30000 memory allocations and will therefore be rather on the slow side. Do you really need such a large array?

monkey0506

#4
Well...I could alternatively set up functions to dynamically retrieve the text of the option halves instead of storing them statically...Not as easy to work with, but I suppose it should work.  Will 15000 take a long time to load as well (I would assume it would take half as long but then I could be wrong)?

[EDIT:]

It's taking...about half as long now...but that's still too long...As for needing such a large array, the problem is that I'm working on the dialog system.  The built-in default allows for 500 dialog topics, and 30 dialog options per topic.  That comes up to 15000 dialog options per game.  True, most users will not reach this number, but that's why it is so high...because it's a reasonable maximum.  However, short of expecting the user to increase the value of the array size every time they want to add another option (and accept another drop in loading speed), I don't see how else I'm supposed to accomodate for this.

For now, at least, I could warn the user that due to the large number of Strings that must have memory allocated to them there is approximately a 30 - 45 second loading time...but it would seem unreasonable (to me at least) to sacrifice that much loading speed for scrollable dialog options.  The user would already be forced to put all their dialogs into the script (which in some ways can make it more complicated, some ways easier).

Any suggestions would be greatly appreciated.  Thanks. :-\

Pumaman

Well, do you absolutely have to intialize them to a blank string? They will be automatically initialized to null, perhaps the part of the script that uses the strings could simply check if they're null and accomodate that.

monkey0506

#6
I tried that but then other things started screwing up...perhaps it was just me trying to work on scripting when my mind was elsewhere...I'll check again...Using that 3 million member char array doesn't sound like too hot of an alternative...

I'll let you know what happens.

[EDIT:]

Thanks Chris, I think I got it working...it loads really fast now...and apart from some bugs* I've managed to work in, I think I've just about got it...

*Nothing to do with null pointers...other errors that I've somehow managed to create.  I got rid of all the null pointer issues. :D

SMF spam blocked by CleanTalk