[SORTED!]Wrong number of parameters...

Started by Technocrat, Tue 04/10/2011 11:39:16

Previous topic - Next topic

Technocrat

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".

Code: ags

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...

Code: ags

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!

Calin Leafshade

well the function names are different for a start.

Technocrat

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.

Khris

#3
Do you have an import line in the header?

Technocrat

Aahhhhh, brilliant! That's gotten it working. Many thanks!

Khris

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.

Technocrat

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!

pcj

You don't need to export functions, by the way.
Space Quest: Vohaul Strikes Back is now available to download!

Khris

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.

Technocrat

So, I should put "import" in the header file "extrascripts.ash", rather than the header for globalscripts.ash?

Khris

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.

monkey0506

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.

SMF spam blocked by CleanTalk