Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: SupSuper on Tue 24/04/2007 12:05:53

Title: Workarounds for parameter limit (I come up with them, you pick one)
Post by: SupSuper on Tue 24/04/2007 12:05:53
So, I was calmly working on my module when all of a sudden "Script link failed: Runtime error: unresolved import 'Gooey::Animate^11'". Oh crap, I finally did it, I broke AGS with my grossly lazy code. So, time to start cutting down on my function.

This is what I currently have. It basically looks for an empty spot in the array and assigns stuff to it.

static function Gooey::Animate
(GUIControl* targ,
int norm_viw, int norm_lop,
int min_viw, int min_lop,
int mout_viw, int mout_lop,
int mdown_viw, int mdown_lop,
int mup_viw, int mup_lop)
{
  int i = 0;
while (i < 20)
{
if (gooey_animate[i].target == null)
{
gooey_animate[i].target = targ;
gooey_animate[i].norm_view = norm_viw;
gooey_animate[i].norm_loop = norm_lop;
gooey_animate[i].min_view = min_viw;
gooey_animate[i].min_loop = min_lop;
gooey_animate[i].mout_view = mout_viw;
gooey_animate[i].mout_loop = mout_lop;
gooey_animate[i].mdown_view = mdown_viw;
gooey_animate[i].mdown_loop = mdown_lop;
gooey_animate[i].mup_view = mup_viw;
gooey_animate[i].mup_loop = mup_lop;
gooey_animate[i].status = eGooey_None;
return;
}
i++;
}
}

So it'd be called like so:

Gooey.Animate(btnHover1, 2, 0, 2, 1, 2, 2, 2, 3, 2, 4);


My first idea was to have an array:

static function Gooey::Animate
(GUIControl* targ, int views[10])
{
  int i = 0;
while (i < 20)
{
if (gooey_animate[i].target == null)
{
int j = 0;
while (j < 20)
{
if (views[j] == null) views[j] = 0;
j++;
}
gooey_animate[i].target = targ;
gooey_animate[i].norm_view = views[0];
gooey_animate[i].norm_loop = views[1];
gooey_animate[i].min_view = views[2];
gooey_animate[i].min_loop = views[3];
gooey_animate[i].mout_view = views[4];
gooey_animate[i].mout_loop = views[5];
gooey_animate[i].mdown_view = views[6];
gooey_animate[i].mdown_loop = views[7];
gooey_animate[i].mup_view = views[8];
gooey_animate[i].mup_loop = views[9];
gooey_animate[i].status = eGooey_None;
return;
}
i++;
}
}

So it'd be called like so:

int view[10];
view[0] = 2;
view[1] = 0;
view[2] = 2;
view[3] = 1;
view[4] = 2;
view[5] = 2;
view[6] = 2;
view[7] = 3;
view[8] = 2;
view[9] = 4;
Gooey.Animate(btnHover1, view);

The downside is, well, the user has no idea what each value is for without constantly looking up the documentation (not that the old method was any clearer, but I would fix that... eventually :P ). And it looks like an awful lot of code, but you could use while loops or some such thing for it. Plus you could have optional parameters in any order.

My other idea is having a pseudo-pointer:

static function Gooey::Animate()
{
  int i = 0;
while (i < 20)
{
if (gooey_animate[i].target == null)
{
gooey_animate[i].target = null;
gooey_animate[i].norm_view = 0;
gooey_animate[i].norm_loop = 0;
gooey_animate[i].min_view = 0;
gooey_animate[i].min_loop = 0;
gooey_animate[i].mout_view = 0;
gooey_animate[i].mout_loop = 0;
gooey_animate[i].mdown_view = 0;
gooey_animate[i].mdown_loop = 0;
gooey_animate[i].mup_view = 0;
gooey_animate[i].mup_loop = 0;
gooey_animate[i].status = eGooey_None;
return i;
}
i++;
}
}

So it'd be called like so:

int i = Gooey::Animate();
gooey_animate[i].target = btnHover1;
gooey_animate[i].norm_view = 2;
gooey_animate[i].norm_loop = 0;
gooey_animate[i].min_view = 2;
gooey_animate[i].min_loop = 1;
gooey_animate[i].mout_view = 2;
gooey_animate[i].mout_loop = 2;
gooey_animate[i].mdown_view = 2;
gooey_animate[i].mdown_loop = 3;
gooey_animate[i].mup_view = 2;
gooey_animate[i].mup_loop = 4;

This last method looks nice in theory. Gooey::Animate finds and initializes a spot for the user to fill in the values, you can easily cut down on lines if you're not gonna use every value (optional parameters), plus you can actually read what it does. The downside is exposing the gooey_animate[] array means the user can play all kinds of unexpected havoc if he wants. And then I have to clean up the mess. :P

Thoughts?
Title: Re: Workarounds for parameter limit (I come up with them, you pick one)
Post by: Khris on Tue 24/04/2007 13:44:05
Not that intuitive, but easy:

Gooey.Animate(btnHover1, "2021222324");

static function Gooey::Animate(GUIControl*trag, String par) {
  ...
  String s;
  s=par.Substring(0,1);
  gooey_animate[i].norm_view=s.AsInt;
  s=par.Substring(1,1);
  gooey_animate[i].norm_loop=s.AsInt;
  ...
}
Title: Re: Workarounds for parameter limit (I come up with them, you pick one)
Post by: SupSuper on Tue 24/04/2007 15:30:37
I think a user can have more than 9 views and 9 loops though. Although I could make it break strings like "10,0,5,2,4,39" into integers. Something like:


static function Gooey::Animate(GUIControl*trag, String par) {
  ...
  int i = 0;
  String s = "";
  while (i < par.Length)
  {
    if (par.Chars[i] == ",")
    {
      gooey_animate[i].norm_view=s.AsInt;
      s = "";
    }
    else
    {
      s.AppendChar(par.Chars[i]);
    }
  }
  ...
}


...dammit, I'm never sticking with a method at this rate. :P
Title: Re: Workarounds for parameter limit (I come up with them, you pick one)
Post by: Khris on Tue 24/04/2007 15:38:40
Sounds even better, I'd use that. Although you won't get around doing it without a loop unless you'd use two-dimensional arrays.