Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Tue 04/10/2011 11:39:16

Title: [SORTED!]Wrong number of parameters...
Post by: Technocrat on Tue 04/10/2011 11:39:16
So, there's a lot about functions I don't quite understand, and I was wondering if you could explain to me what's going wrong with this. What I've been making is a script to cause a chosen GUI to swoosh into the view on a decelerating path, appear to overshoot and bounce, then move to the centre. That's not the problem I'm having, and I'll worry about it later. The issue I've got is that every time I try to run this function, it complains about having the "wrong number of parameters".


function TechnoGUIBounceIn(GUI *BounceGUI){
 BounceGUI.X = -10 - BounceGUI.Width;
 BounceGUI.Visible=true;
 int centring = (320-BounceGUI.Width)/2;

 int BounceMoveSpeed = FloatToInt((IntToFloat(centring) - IntToFloat(BounceGUI.X))/5.0);
 
 while(BounceGUI.X<centring+10){BounceGUI.X+=BounceMoveSpeed; BounceMoveSpeed = FloatToInt((IntToFloat(centring) - IntToFloat(BounceGUI.X))/5.0); Wait(1);}
 while(BounceGUI.X>centring){BounceGUI.X--;Wait(1);}
 
 
}


And then later...


if (keycode == 'I') TechnoBounceIn(gHelp1);


But as I say, what I get is "Wrong number of parameters to call 'TechnoBounceIn'". What have I misunderstood about making functions?

Many thanks!
Title: Re: Wrong number of parameters...
Post by: Calin Leafshade on Tue 04/10/2011 12:16:06
well the function names are different for a start.
Title: Re: Wrong number of parameters...
Post by: Technocrat on Tue 04/10/2011 12:23:55
Quote from: Calin Leafshade on Tue 04/10/2011 12:16:06
well the function names are different for a start.

Ah, mistype on my part here on the forum. In the script, it matches.
Title: Re: Wrong number of parameters...
Post by: Khris on Tue 04/10/2011 12:30:10
Do you have an import line in the header?
Title: Re: Wrong number of parameters...
Post by: Technocrat on Tue 04/10/2011 12:45:22
Aahhhhh, brilliant! That's gotten it working. Many thanks!
Title: Re: [SORTED!]Wrong number of parameters...
Post by: Khris on Tue 04/10/2011 13:46:54
Although this is solved, I'm not entirely sure what was happening here, could you clarify:

Where did you put the function body? Is it in the global script, above on_key_press?

Where did you try to call the function?

A missing import line shouldn't produce this kind of error but maybe I'm missing something here.
Title: Re: [SORTED!]Wrong number of parameters...
Post by: Technocrat on Tue 04/10/2011 17:14:11
Quote from: LeKhris on Tue 04/10/2011 13:46:54
Although this is solved, I'm not entirely sure what was happening here, could you clarify:

Where did you put the function body? Is it in the global script, above on_key_press?

Where did you try to call the function?

A missing import line shouldn't produce this kind of error but maybe I'm missing something here.

The body of the function is in a different script, exported then imported in GlobalScript's header. First, I tried calling the function in on_key_press, but that wasn't doing anything (which is an unrelated issue that I understand), and the whole thing was running successful when I called it from an interaction with a hotspot. No idea how it's working, but for the kind of cargo-cult coding I do, as long as it gets results, that's a good start for me!
Title: Re: [SORTED!]Wrong number of parameters...
Post by: pcj on Tue 04/10/2011 17:46:01
You don't need to export functions, by the way.
Title: Re: [SORTED!]Wrong number of parameters...
Post by: Khris on Tue 04/10/2011 18:09:13
In general, if you put a function in another script, you should put the import line in the corresponding header, not the global one.
That way, every script further down the tree and all room scripts can use the function.
Title: Re: [SORTED!]Wrong number of parameters...
Post by: Technocrat on Tue 04/10/2011 19:25:55
So, I should put "import" in the header file "extrascripts.ash", rather than the header for globalscripts.ash?
Title: Re: [SORTED!]Wrong number of parameters...
Post by: Khris on Tue 04/10/2011 21:17:49
If you're using only one extra script, it doesn't really matter.

The header parts are included in every subsequent script, so if you had

A
B
GlobalScript

then importing a function defined in A only in the GlobalScript's header would make it invisible to B.
Title: Re: [SORTED!]Wrong number of parameters...
Post by: monkey0506 on Wed 05/10/2011 04:05:38
Also, a function defined in B would never (EVER) be available to A, even if you made it "visible" by putting an import in A's header.

You can import a function any time before it's defined.

You can only use a function after it's been defined.