Confused about GUI Scripting

Started by rock_chick, Thu 05/07/2007 04:59:00

Previous topic - Next topic

rock_chick

Lots of tutorials and such out there for it are made for the pre 2.7 version so aren't that helpful. I looked through the manual but just got very confused trying to find what I was looking for. Basically the script to run the command for what each button does when it's clicked. Tried a few things but errors came up so I'm a bit lost here.

Scorpiorus

Ok let's do it step by step:

1. In the GUI Editor, add a new button to some GUI
2. Give this button a Script Name, eg: buttonOK (see a list of properties displayed in a small window)
3. Next double click the button itself and click Ok. The script editor will open and the following code will be added to the main global script:

Code: ags

function buttonOK_Click(GUIControl *control, MouseButton button) {

// put your code for the button here

}


That is where you put the scripts to be run on clicking the button, for example:

Code: ags

function buttonOK_Click(GUIControl *control, MouseButton button) {

    Display( "You have just clicked OK!" );

}


Let us know if it works for you :)

rock_chick

#2
I feel a bit silly about not being to work this whole scripting thing out but I tried theses to get the button to display the save dialog but they didn't work.
Code: ags
function save_Click(GUIControl *control, MouseButton button) {
SaveGameDialog ()
}

Code: ags
function save_Click(GUIControl *control, MouseButton button) {
SaveGameDialog
}

I guess I'm looking for these bits of script use for my GUI buttons.
Bringing up the save game dialog
Bringing up the quit dialog
Walk
Look
Talk
Pickup
Touch(or I think it's called interact)
Inventory

Ashen

Looks like you misread this bit of Scorpiorus' post:
Quote
3. Next double click the button itself and click Ok. The script editor will open and the following code will be added to the main global script:

That's just an example code, based on a new GUI Control (buttonOK). It doesn't exist in the default script. The save_Click function you found refers to an existing GUI Control in your game (most likely a Button called 'save').

Double-clicking existing, named Controls will open the editor to the proper point (if it exists), or create the control function if needed (as in Scorpiorus' post).
I know what you're thinking ... Don't think that.

Scorpiorus

#4
Yep, exactly what Ashen said!

As for your code, rock_chick, it's almost correct. Just add a semicolon at the end of the line and it should compile with no errors:

function save_Click(GUIControl *control, MouseButton button) {
    SaveGameDialog();
}


Changing the cursor mode to TALK, for example, would look something like this:

function TalkTo button's Script Name here_Click(GUIControl *control, MouseButton button) {
    mouse.Mode = eModeTalkto;
}

Khris

If you *did* create a button, name it "save" and double-click it:
Try
SaveGameDialog();

Quote from: rock_chick on Sun 08/07/2007 19:25:51
I guess I'm looking for these bits
It's QuitGame(1); mouse.Mode==eMode...; and show_inventory_window();

rock_chick

I wasn't misreading the post, it was merely that I didn't realise I needed to add the ; after SaveGameDialog, I see now that that is needed for ending these script bits so I will keep that in mind. Seems to be working, thanks!

Ashen

Quote
I wasn't misreading the post,
You edited your post after I'd replied - I'll admit my post doesn't make much sense now. In the original post, it read like you were having trouble finding the buttonOK_Click function, I was just pointing out that you shouldn't have been able to, so that wasn't a problem.

Quote
I guess I'm looking for these bits
To expand on what KhrisMUC said, you should also be able to get the other code bits you need by studying the ICONBAR GUI in the default game template (and like I said, double-click them in the editor to open the script at the right point). Changing cursor mode doesn't need script - just use the 'Change Cursor mode' option for the Left click property.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk