Calling a function to run which is already defined not working

Started by mrsix, Sun 19/10/2008 19:46:09

Previous topic - Next topic

mrsix

I will give an example.

I have this small script:

-----------------------------
function TelDial_OnClick(GUIControl *control, MouseButton button) {
if (PhoneLabel.Text=="5551552")
{
PlaySound (5);
Wait(160);
cEgo.ChangeRoom(3);
gGui3.Visible=false;

}

else
{PlaySound (4);
Display ("Wrong Number");
PhoneLabel.Text=("");
}
}
-------------------------------

Basically, when I press the button, that code works.
But, I want this piece of code to work everytime there is a variable which hits a certain number, but without having to press the button, so in theory you can just call the name of the function and it will run anytime. So I have this peice of code to check it:

--------------
function repeatedly_execute() {
   
  if (TelephoneCounter==7){
TelDial_OnClick;}
  }
-----------

Everytime I try to run it says 'GlobalScript.asc(105): Error (line 105): Undefined token 'TelDial_OnClick'


I check the userguide and it says about importing/exporting functions, but both of these bits of code are in the global script, so my understanding is that this is not necessary.
My first thought is that  '_OnClick' is an actual peice of code, so I tried renaming the function, it still didnt work.

Any ideas? Sorry if this a stupid question, normally its something silly (always the way!)

Thankyou for your help

Khris

A function must be defined before it can be called.
Just move your function to the top of the global script (or above rep_ex).

mrsix

THank you for your help!

I think I got further with it, but now I have this error message:
"GlobalScript.asc(122): Error (line 122): Not enough parameters in call to function"

The Rep_ex code says:
--
function repeatedly_execute() {
   
  if (TelephoneCounter==7){
TelDial_OnClick();
TelephoneCounter=0};}
---

I dont understand the error message really. Does it mean not enough parameters define when the function should be called? It seems straight forward in the code!

Pumaman

The OnClick function is defined like this:

function TelDial_OnClick(GUIControl *control, MouseButton button) {

and that's how it has to be, because it is a built-in event handler. If you want to call it manually, you would need to do:

TelDial_OnClick(TelDial, eMouseLeft);

ie. fill in those two parameters.

mrsix

Thank you, I have got it fixed thanks to your reply.
It works fine! My only problem is that I dont understand what the brackets actually refer to (telDial, Emouseleft), but who cares, it works now!! I shall read up on this and find out.

Thanking you for your assistance  :)

Trent R

The two parameters were needed, and so you had the fill in the what was required in the function, a GUIControl (such as your button, TelDial) and a MouseButton (eMouseLeft just says that you've click with the left mouse button.)


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Khris

You can click GUIControls with the right mouse button, too, so one might choose not to react/react differently to a right-click.
The clicked GUIControl is passed to the function to react individually if one has many similar buttons (e.g. a keypad) and uses the same OnClick function for all of them.

SMF spam blocked by CleanTalk