Author Topic: GUI global script that impacts a room object/script  (Read 205 times)

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

Re: GUI global script that impacts a room object/script
« Reply #1 on: 20 Jan 2021, 19:22 »
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: Adventure Game Studio
  1. // in the room's rep-exec:
  2. if (DoorOpened == true)
  3. {
  4.   // Animate the Door
  5.   // Play a sound
  6.   DoorOpened = false;
  7. }
  8.  

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).

Re: GUI global script that impacts a room object/script
« Reply #2 on: 20 Jan 2021, 19:30 »
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.
« Last Edit: 20 Jan 2021, 20:05 by Crimson Wizard »

Re: GUI global script that impacts a room object/script
« Reply #3 on: 20 Jan 2021, 19:53 »
Thank you both for your answers!