Lua Build Series - Digital Throttle - Stormworks
Building a Digital Throttle
Overview: In this episode, the speaker will show viewers how to build a digital throttle using Max. The speaker will go through all the components and logic needed to build the throttle, and then test it in the world of Snow Monks.
Components Needed
- Battery
- Screen (2x2)
- Doll
Building the Market Processor
- Create a new market processor and set it to 2x2
- Add three nodes: composite from touch screen, output video, and output number for throttle
- Add Lua script to draw a white line on the left side of the screen (10px from top, 10px from bottom)
- Call the market processor "On Screen Throttle"
- Place the market processor onto the creation and connect the video and composite
Adding Logic
- Add logic to detect when the line is clicked
- Add logic to calculate the percentage of the throttle based on the click position
- Add logic to output the percentage to the doll
Testing the Throttle
- Test the throttle by clicking on the line and observing the doll's movement
- Ensure that the throttle is working correctly and that the doll moves between 0% and 100%
Adding a Dowel to the Screen
Overview: This section covers how to add a dowel to the screen using a red button.
Creating a Rectangle
- Set the color of the rectangle to red (200, 0, 0).
- Set the width of the rectangle to 5 and the height to 3.
- Place the rectangle at 10x and 54y to center it.
Getting Inputs from the Touch Screen
- Use input X (channel 3) and input Y (channel 4) from the touch screen to control the height of the button.
- Use a memory register to save the number from the touch screen.
- Use a read number to read the number from the touch screen.
- Use a set to save the number from the touch screen.
- Use a write number to feed the composite back into Oliver.
Limiting the Button's Movement
- Use a clamp to limit the number from the touch screen between 10 and 54.
- Update the script and spawn it in.
- Use a button to draw the rectangle.
- Press done and set the reset value to the bottom of the line (54).
- Clamp the number from the touch screen between 10 and 54.
Throttle Control with Lua Scripts
Overview: This section covers how to limit someone from pressing anywhere on the screen and how to read a throttle number using Lua scripts.
Limiting Screen Presses
- Use the
point_rectangleblock to set the dimensions of where someone can press on the screen.
- Add three buttons at the top of the script to read where someone is pressing.
Reading Throttle Number
- The throttle number is going from 54 down to 10.
- Use two function blocks to convert the number into a percentage from 0 to 100.
- Subtract the starting point (54) from the height (44) and divide by 44.
- Multiply the result by 100 to get the percentage.
Introduction to Lua Scripting
Overview: This video provides an introduction to Lua scripting, a programming language used to create digital throw switches.
Creating a Digital Throw Switch
- Press the "Lua Script" button to begin creating a digital throw switch.
- Utilize the help menu to find the necessary memory registers and function blocks.
- Link to the workshop in the video description for a downloadable version of the script.
Conclusion
- Provide feedback on the video and suggest topics for future videos.
- Thank viewers for watching and provide a conclusion.
Turn any video into a summary like this
YouTube links, meetings, lectures — with transcripts, search, and chat.