BUG of some sort with # of parameters per function

Started by monkey0506, Fri 04/08/2006 18:47:41

Previous topic - Next topic

monkey0506

EDIT: I've changed the title thread again, because apparently this is some type of bug as you should already be able to have up to 15 parameters per function.

Okay, I'm converting this thread to a suggestion thread. Simply because it was already here, the situation is explained below, and Rui seconded the motion here.

The suggestion is that we can (please?) have more parameters allowed for each function (9 is the current limit).

Question involving the game crashing with function using 10 parameters

I have the following code for my PersistentSpeech module:

Code: ags
// module header
managed struct PersistentSpeech {
  /* ... */
  import static Overlay* Say(int index, Character* Char, String Text, int width, int font, int xOffset = 0, int yOffset = 0, bool runanim = false, int loops = -1/*, bool ignorePausedStatus = true*/);
  };

// module script
static Overlay* PersistentSpeech::Say(int index, Character* Char, String Text, int width, int font, int xOffset, int yOffset, bool runanim, int loops/*, bool ignorePausedStatus*/) {
  if ((Char == null) || (Text == null) || (loops < -1) || (width < 0) || (font < 0) ||
  (PersistentSpeech_CharacterInUse(Char, index)) || (index < 0) ||
  (index >= ePersistentSpeech_MaxItems)) return null;
  if (loops == -1) loops = GetGameSpeed() * FloatToInt(IntToFloat(Text.Length + 1) / 15.0, eRoundUp);
  PersistentSpeech_Character[index] = Char;
  PersistentSpeech_Loops[index] = loops;
  PersistentSpeech_Text[index] = Text;
  if ((PersistentSpeech_Overlay[index] != null) && (PersistentSpeech_Overlay[index].Valid))
    PersistentSpeech_Overlay[index].Remove();
  ViewFrame* frame = Game.GetViewFrame(Char.View, Char.Loop, Char.Frame);
  int x = Char.x + xOffset - (GetTextWidth(Text, font) / 2);
  int y = Char.y + yOffset - FloatToInt(IntToFloat(Game.SpriteHeight[frame.Graphic]) * 1.5);
  frame = null;
  int t_width = GetTextWidth(Text, font);
  if (t_width > width) t_width = width;
  if (x < 0) x = 0;
  if (x + t_width > System.ViewportWidth) x = System.ViewportWidth - t_width;
  if (y < 0) y = 0;
  if (y + GetTextHeight(Text, font, width) > System.ViewportHeight) y = System.ViewportHeight - GetTextHeight(Text, font, width);
  PersistentSpeech_Overlay[index] = Overlay.CreateTextual(x, y, width, font, Char.SpeechColor, Text);
  if ((runanim) && (Char.SpeechView > 0)) {
    Char.LockView(Char.SpeechView);
    Char.Animate(Char.Loop, Char.AnimationSpeed, eRepeat, eNoBlock, eForwards);
    PersistentSpeech_CharacterViewLocked[index] = true;
    }
  else PersistentSpeech_CharacterViewLocked[index] = false;
  /*PersistentSpeech_IgnorePaused[index] = ignorePausedStatus;*/
  return PersistentSpeech_Overlay[index];
  }


I commented out the bool ignorePausedStatus because without it, the game compiles and runs fine. However when I include it (and yes I am sure the parameter is included in both the header and the script), it crashes the game with the following error:

Quote---------------------------
Adventure Game Studio
---------------------------
Script link failed: Runtime error: unresolved import 'PersistentSpeech::Say^10'

---------------------------
OK   
---------------------------

I understand that this means it can't find the function definition, however I don't see why it can find it when it has 9 parameters but it can't when it has 10.

BTW, I am trying to add the parameter because the way it is set up now the persistent speech ignores whether the game is paused. This could be considered a feature so I don't want to remove it, however the user could also want the Overlay to remain valid as long as the game is paused (in addition to the set amount of game loops).

GarageGothic

AGS only supports up to 9 parameters for function calls, sorry. I hope you can find a workaround.

monkey0506

What?

Hmm...I did some testing with some other functions and got it to support up to 14 parameters......

In any case I suppose a global setting via an enumerated value could serve as a workaround.

GarageGothic

Well, this is from strazer's AGS tidbits & snippets page:

CJ: "Yes, the script engine has a limit of 9 parameters in a function call."

monkey0506

Ok, that's fine...maybe I should suggest here that CJ increases the limit then.

The link is broken ("http://http//") by the way.


Rui 'Trovatore' Pires

Only up to 9? How odd, I have a function that has 10 parameters and 9 are optional. Never gave me trouble... but then I never did call more than 5...

...in any case, I support the increase of the limit, CJ. Up to 15 or so, and that'll probably please the most demanding and messy coder. :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

Okay, the thread is suggestionized now.

Strangely enough it seems that although the limit is 9 parameters you can sometimes have more, but not always. Like I said, I've had functions with 14 parameters before...

Pumaman

You should be able to have up to 15 parameters to a function, I'll have a look at it.

Radiant


monkey0506

Well like CJ said, "[we] should be able to have up to 15"...so this is apparently some sort of bug. And the number of parameters available per function seems somewhat random to me...

SMF spam blocked by CleanTalk