Modules - How to make them and use them?

Started by theswitch, Sat 27/08/2005 00:58:02

Previous topic - Next topic

theswitch

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 :-[

RickJ

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.   


theswitch

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?

monkey0506

Well as far as I know they have to stay in the global script... :-\

theswitch

oh no, I thought this could be done with the module manager, its in the manual under module (in the index)


monkey0506

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

theswitch

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)

monkey0506

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

theswitch

thanks, I probibly would have figured that out but you save me some time, thanks, I think this solves my problem. . .we'll see ;)

theswitch

#9
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??

strazer

#10
If I understand you correctly, you could try using the on_event function:

Code: ags

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

theswitch

ahh, I couldn't figure out how to use on event for a single button, I'll have to try that out :)

theswitch

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

strazer

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.

theswitch


strazer

Oops, my bad, it's eEventGUIMouseDown. :)

Btw, these events can be found in the manual under Reference -> Scripting event reference.

theswitch

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


SMF spam blocked by CleanTalk