Incrementing Number Trigger Tutorial
From C4 Engine Wiki
(Redirected from Incrementing Number Trigger)
Contents |
Creating the elements
- Create a box (in the top view) using the Geometries page
- Create a box trigger around the box using the Trigger page
- Draw a panel in the front view using the Effects page
Setting up the panel
- Go to the panel info (ctrl-I), go to the Controller tab
- Set "Interface width" and "Interface height" to 64 (so that the text fills the panel - otherwise you can increase the Text Scale)
- Click "Edit Panel"
- Draw a text box using the Text tool from the "Items" group
- Set the text to what you want it to initially display. e.g. 0 or nothing
- In the Item Settings, under General Settings, set the "Widget identifier" to TXT1 and click OK
Connecting the trigger to the panel
- In the trigger's "Node Info" window add a new connector with the key PAN1 and press OK
- Change to "connect nodes" mode (hotkey "5")
- Select the box trigger then select "PAN1" then select the panel
- In the menu go to "Node" then "Connect Node" (or use the hotkey Ctrl-L)
Setting up a script in the connection marker
- Go back to the box trigger "Node Info" window, switch to the "Controller" tab and change the controller type to script and go to "Edit Script"
- In the Script Editor, create a new variable called Count. Give it the type "Integer" (a whole number) and scope "Object" (so that its value is remembered)
- Add an "Evaluate Expression" method with Count + 1 as the expression and Count as the output variable
- Add a "Call Controller Function" method. Use the "Draw Fiber" tool to connect "Count = Count + 1" method to the latest method
- Edit the "Call Controller Function" method - set the Target Node to "Connector PAN1" and select "Set Item Text" from the Functions list
- In the Function Settings, set "Target item identifier" to TXT1, "Panel item text" input variable to Count, "Text combine mode" to Replace, and "Max result length" to the max number of digits you want - e.g. 3 and press OK
Adding a sound effect
The trigger can be edited so that when triggered a sound also plays. See the Sound Trigger Tutorial
