How do I trigger an event by clicking a GUI button? *SOLVED

Started by Lolita-Marshmallow, Wed 06/07/2011 22:36:45

Previous topic - Next topic

Lolita-Marshmallow

I've looked through all the tutorials and googled for hours, yet I cannot find help for this.

???Simple explanation: I want to trigger a cut scene when I click "Yes" on a GUI.

The GUI and the cut scene work fine apart, but not together.

What happens is if I post the script in the room, the GUI does not respond.
If I post the script in the global area, the cut scene in that room does not respond. (The script doesn't recognize the objects in the room's scene. If I try to define them, it says they already are defined).

Example:
Player interacts with the trash can. GUI appears: "Do you want to tip it over?" Yes/No?
Yes: GUI closed. Player tips the trash over.
No: GUI closed.

The GUI closed just fine with Yes and No, but no cut scene on Yes.

Here is my script:

//In the room. Click trashcan and GUI opens.


function Can_Interact()
{
 gTrash.Visible = true;
 }

//For buttons in the global area.

function bNo_OnClick(GUIControl *control, MouseButton button)
{
 gTrash.Visible = false;
}

function bYes_OnClick(GUIControl *control, MouseButton button)
{
gTrash.Visible = false;
StartCutscene(eSkipESCOnly);
cAlice.Walk(163, 103, eBlock, eWalkableAreas);
Can.Visible = false;
CanTip.Visible = true;
EndCutscene;
}

//Alice walks over and knocks over the trashcan.

Please help if you can.



Khris

There are multiple solutions to this:

1)
You can use CallRoomScript().
In bYes_OnClick, call "CallRoomScript(1);", then add this to the room script:
Code: ags
void on_call(int event_number) {

  if (event_number == 1) { // event #1: tip over trashcan
    ...  // cutscene commands
  }
}


2)
In bYes_OnClick, set a global bool variable to true (create it in the Global variables pane, name "tip_over_trashcan", type: bool, initial value: false).
Add the room's repeatedly_execute event, then put this inside the function:
Code: ags
function room_RepExec() {

  if (tip_over_trashcan) {
    tip_over_trashcan = false;
    ... // cutscene commands
  }
}


3)
Kinda untidy, but the quickest way:
You can reference objects in the global script by their ID:
Code: ags
function bYes_OnClick(GUIControl *control, MouseButton button) {

  gTrash.Visible = false;
  StartCutscene(eSkipESCOnly);
  cAlice.Walk(163, 103, eBlock, eWalkableAreas);
  object[2].Visible = false;
  object[3].Visible = true;
  EndCutscene();        // <-- note the parentheses
}


Replace 2 and 3 with the actual IDs of the objects.

Lolita-Marshmallow

Thank you so much. That looks like it will work. :)

SMF spam blocked by CleanTalk