Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: theswitch on Sat 27/08/2005 00:58:02

Title: Modules - How to make them and use them?
Post by: theswitch on Sat 27/08/2005 00:58:02
OK OK I know, this is SOMEWHERE on the forums, but I can't find it, its not in thye bfaq ether (hint hint)

yea I can make a module in the module manager, I make the header import function bla bla bla, BUT I want it to work on mouse click of a certain button, now mabe this is the wrong part. . . when I double click the button first time (in gui editor) it adds a section to the global script and in this sectoion I can put in the stuff I want to happen, now mabe the default functin code it gives me is wrong

function test_button_Click(GUIControl *control, MouseButton button)

I copy/pasted this into my module header also saying Import before the above text ofcourse,


so I guess I'm supposed to get rid of the above and use on_mouse_click (MouseButton button)

BUT
the manual doesn't give me enough info on how to use it (as I'm new to scripting). . . . (as youv noticed by now :))

so all I'm saying is how do you make a button exicute code from a module at any time in the game (while the buttons there)

I'm suprised there isn't a tutorial on a simple thing like this, or mabe I'm just SLOW :-[
Title: Re: Modules - How to make them and use them?
Post by: RickJ on Sat 27/08/2005 01:58:17
I don't believe you can just cut and paste GUI event handlers like that.  AGS probably expects to find that function in the global script where it created it.   What I would suggest is that you call a module function from the button click handler function.

There was a discussion a while back about how to create modules for public consumption.   The goal is that modules from multiple authors should be able to work together.    You can find that discussion here:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=18989.msg231569#msg231569

You may also find these documents useful as well.  They aren't tutorials per se but they should be helpful.   

Title: Re: Modules - How to make them and use them?
Post by: theswitch on Mon 29/08/2005 22:52:05
ok I had another go at it and got kinda lost. . . agien, anyways, my first post here was a liitle messy, so I'll make it a bit clearer

all I want to do is have my button click scripts to be seperate from the global script, because right now everythings in the global script, thats all, whats the easyest way to do this?
Title: Re: Modules - How to make them and use them?
Post by: monkey0506 on Mon 29/08/2005 23:47:26
Well as far as I know they have to stay in the global script... :-\
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Tue 30/08/2005 15:03:08
oh no, I thought this could be done with the module manager, its in the manual under module (in the index)

Title: Re: Modules - How to make them and use them?
Post by: monkey0506 on Tue 30/08/2005 16:01:02
QuoteThe main global script still has to contain all the interaction functions (Look At Character scripts, Interact With Inventory scripts and so forth).

Clicking a button is in fact an interaction.

[EDIT:]  Unless of course you meant:

QuoteCan script modules use special functions like game_start and repeatedly_execute? Well, yes and no.

But there is no interface_click(the predecessor to the btnname_click(), etc. functions) function available, so it wouldn't be called even if you put it there...
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Tue 30/08/2005 16:22:50
auhh man, thst just SUCKS (or insert any other 14 year old term), I guess I'll have to think up a way to use those limited commands to break up my scripts, can you have more than one sepeate script that uses repeadidtly exicute? (spelling ;D)
Title: Re: Modules - How to make them and use them?
Post by: monkey0506 on Tue 30/08/2005 17:15:04
Yes you can make as many SMs as you want (within AGS's limit of SMs...I don't know what that is) that have a repeatedly_execute function.  Like the manual says, it will be called right before the main rep_ex function (in the global script (also in order of the list of SMs, the first in the list being the first called)).  As long as you spell it right. :=
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Tue 30/08/2005 18:25:43
thanks, I probibly would have figured that out but you save me some time, thanks, I think this solves my problem. . .we'll see ;)
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Wed 31/08/2005 00:33:03
ok I must be getting closer

so my function is repeaditly exicute bla bla etc, but in my script how do I make a button click work without useing a function command? :-\

EDIT: do I call the global function into my module script, so I'd call test_button_Click etc tec??
Title: Re: Modules - How to make them and use them?
Post by: strazer on Wed 31/08/2005 02:44:40
If I understand you correctly, you could try using the on_event function:


// module script

function on_event(EventType event, int data) {

  if (event == eEventGUIMouseDown) { // if a mouse button has been pressed down
    GUIControl *thecontrol = GUIControl.GetAtScreenXY(mouse.x, mouse.y); // get GUI control under mouse cursor
    if (thecontrol != null) { // if a GUI control is there

      if (thecontrol.AsButton == btnMyButton) { // if it's this button
        // do your stuff
      }
//    else if (thecontrol.AsButton == btnMyOtherButton) { // if it's that button
        // do some other stuff
//    }
      // and so on

    }
  }

}


Edit: eEventMouseDown -> eEventGUIMouseDown
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Wed 31/08/2005 16:12:37
ahh, I couldn't figure out how to use on event for a single button, I'll have to try that out :)
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Wed 31/08/2005 21:21:05
can't seem to get the

function on_event(EventType event, int data)

to work.

I checked the docs but I need a little more info on how to set up this funtion, (still learning I guess)

the other stuff doesn't look bad though
Title: Re: Modules - How to make them and use them?
Post by: strazer on Wed 31/08/2005 23:03:13
What's the problem? Do you get an error message? Which one?

There's no need to "set up" anything, just copy the above script into the module script and change the btnMyButton/btnMyOtherButton names to your GUI button names.
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Thu 01/09/2005 00:35:41
undefined symbole eEventMouseDown :-\
Title: Re: Modules - How to make them and use them?
Post by: strazer on Thu 01/09/2005 00:50:54
Oops, my bad, it's eEventGUIMouseDown. :)

Btw, these events can be found in the manual under Reference -> Scripting event reference.
Title: Re: Modules - How to make them and use them?
Post by: theswitch on Thu 01/09/2005 00:59:29
YESSSS

yea it works now, thanks alot, this should do the trick for making many seperate scripts from the global script as most my programming in my game comes from button pushes, thanks alot
Title: Re: Modules - How to make them and use them?
Post by: strazer on Thu 01/09/2005 01:00:39
Glad I could help. :)