Support Home Scripting Lifecycle Methods

Lifecycle Methods

  • Overview
  • Lifecycle Methods
  • construct
  • initialise
  • awake
  • screenStart
  • screenUpdate
  • preProcessResponse
  • scoreResponse
  • processResponse
  • postProcessResponse
  • screenResponsesComplete
  • screenFinish
  • removeListeners
  • destruct
  • Callable Methods
  • triggerResponse

Overview


Lifecycle methods are all the functions that components have that get called by the Gorilla system at specific times. You can add any of them to your component to implement custom behaviour at that point.

For example, there is a function called screenStart which will be called when the screen starts. If you want to implement some of your own logic when the screen starts, you can add it to this function.

Use the menu on the left to browse the full list of lifecycle methods available to you.

construct()

Called when your component is first constructed.

// in your component somewhere public construct() { }

initialise()

Called after your component has been constructed, and all other components in the object's hierarchy have been constructed.

// in your component somewhere public initialise() { }

awake()

Called after your component has been initialised, and all other components in the object's hierarchy have been initialised.

// in your component somewhere public awake() { }

screenStart()

Called when the screen starts

// in your component somewhere public screenStart() { }

screenUpdate()

Called every frame, while this component is on the screen. Use this sparingly; it's necessary for e.g. click-and-drag handling or other operations that need to happen every frame, but most things do not.

// in your component somewhere public screenUpdate() { }

preProcessResponse(response: ProcessedResponse)

Called when a response has been received as part of the response processing pipeline. Only called on ScreenComponents.

// in your component somewhere public preProcessResponse(response: ProcessedResponse) { }

scoreResponse(response: ProcessedResponse)

Called when a response has been received as part of the response processing pipeline. Only called on ScreenComponents.

// in your component somewhere public scoreResponse(response: ProcessedResponse) { }

processResponse(response: ProcessedResponse)

Called when a response has been received as part of the response processing pipeline. Only called on ScreenComponents.

// in your component somewhere public processResponse(response: ProcessedResponse) { }

postProcessResponse(response: ProcessedResponse)

Called when a response has been received as part of the response processing pipeline. Only called on ScreenComponents.

// in your component somewhere public postProcessResponse(response: ProcessedResponse) { }

screenResponsesComplete()

Called when the screen is ready to advance because all responses have been received. This is the last moment where any additional responses can also be logged. If there is any feedback to still display before the end of the screen, it will continue to do so after this function is called, but otherwise the screen will finish on the same frame that this function is called.

// in your component somewhere public screenResponsesComplete(promises: Promise[]) { }

This function also receives an array of promises - you can append your own promise to the array if you want to prevent the screen from advancing until you are ready:

// in your component somewhere public screenResponsesComplete(promises: Promise[]) { promises.push(new Promise((resolve: () => any, reject: () => any) => { // add your logic here // ... // when you're ready, call resolve() resolve(); })) }

screenFinish()

Called when the screen has finished. After this is called, the elements on this screen will be hidden and the elements for the next screen will be shown, and screenStart() will be called for the next screen.

// in your component somewhere public screenFinish() { }

removeListeners()

Called when your component is no longer on the screen. Use this to stop listening for any events that you wouldn't want to 'spill' over into the next screen.

// in your component somewhere public removeListeners() { }

destruct()

Called when your component is about to be destroyed. Use this to release any resources you might have created, if necessary.

// in your component somewhere public destruct() { }

triggerResponse(response: Response)

Trigger a response, passing in a Response object

// in a function in your component somewhere public myFunc() { // do some logic... this.triggerResponse({ response: "myResponse", responseType: ResponseType.Response, }) }