GUI global script that impacts a room object/script

Started by Dariago, Wed 20/01/2021 15:22:47

Previous topic - Next topic

Dariago

Hi,
So here is my question:
I have a room with a locked door. the way to open the door is to insert some code to a panel.
Now,
The code panel is implemented by a GUI. all works fine with the panel - but when the player insert the right code I want the door to be opened automaticly.
How can I do that?
The panel GUI related script is in the Global Script and the door and its script (for example - animation of door being opened, the sound of it etc.) are in a room.
Is there a way to "tigger/messeage" some script code/function from the global script to a room?

(For now I have a work-around: If the code is right, I updated a global variable and the player now can "open" the door by interact event. but the door is not opened automaticly.)

Thanks!

Matti

Quote from: Dariago on Wed 20/01/2021 15:22:47
Is there a way to "tigger/messeage" some script code/function from the global script to a room?

(For now I have a work-around: If the code is right, I updated a global variable and the player now can "open" the door by interact event. but the door is not opened automaticly.)

Setting a global variable is the way to go. You just need to start the animation of the door in the repeatedly execute function after updating the variable.

Code: ags

// in the room's rep-exec:
if (DoorOpened == true)
{
  // Animate the Door
  // Play a sound
  DoorOpened = false;
}


You need to change the variable back so the door will only open once, but you may also check the doors current frame or view (if you're going to change it).

Crimson Wizard

#2
There's also CallRoomScript command that runs a special function in room script named "on_call". You'd need to add such function there yourself, and invent a "code" for your event, which you will use to identify what happened.

More info in the manual: https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_call



Another alternative is to ofcourse script the door opening right in the global script. The difference is that you cannot refer to objects by their script names since they are not accessible in the global script. So only way to do something with them is to access them through global array "object" using object's index, for example "object[5]". This may be not very elegant looking solution, but it exists nonetheless.


SMF spam blocked by CleanTalk