Space Engineers

Space Engineers

41 ratings
Guide to Visual Scripting Tool
By Chipstix213
A guide on how to assemble some simple scripts to control game play for a scenario.
3
2
   
Award
Favorite
Favorited
Unfavorite
Visual Scripting Tool
This guide will show how to construct and understand the example scenario from here
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2804600569


Step 1: Build a grid
In this example, I have a refinery, a cargo box, a button panel and a battery. the button panel is set to be able to turn on the refinery




Step 2: Tag the entities
Pressing f11 twice brings up the scenario menu where you can “Tag” selected items for the scenario

Right-click to pan the camera then Left click to select an item. When selected it will be highlighted in dark blue.


Rename selected Entity “Tags” the grid

Selected Block “Tags” highlighted item

I have called the grid “Main_Base” and named all the functional blocks by their type “Refinery_1”, “Cargo_1” Button_1” & “Battery_1”



Once you are done, put your character where you want the player to start and save.

Step 3: Now it's time to start the VST tool.

When you load up the visual scripting tool choose saved world and pick the save you just created


To verify the connection press the run scenario button and you should get a “hello world” chat message.





As the last script in the state machine, it will end the scenario.

Additionally using a finished state to the line will close out the session with the option of unloading the game and rolling keen credits. Right-click and choose final then drag a connection from the “end” objective script over the final block to connect.
Detail about the tool
Step 4: time to add logic!

Below is the default script that will be inside the mission 01 start script in your scenario from the start.



Explanation of types of nodes,
-Methods in Mission script this will be the logic running throughout the whole session
GameStarted - runs on initial world load
GameFinished - runs through once on stare machine completed
Update - runs once per game tick
Dispose - runs through once on world unload
PlayerDied - trigger when the player dies default to “death screen” and unloads world.



-Methods in objective scrips, these are separated with transitions as your scenario progresses
-init - runs through once on script load
This will be where you want to place all the setup blocks and questlog.

-Update runs through once per game tick
This will be where the interactive items will be attached

-Dispose - runs through once on script unload


-Deserialize - not used



-Events
-Begins a Sequence Line execution when the associated event occurs in the game.
-Single Sequence Line output and parameter pins, no input pins
-Dark orange



​ -Key Events:
-Functions similarly to normal Events, but with user-specified “key” values
-Only fires when parameters with the specified values are triggered



-Functions:
-Methods loaded from libraries
-Input and output connections for parameters
-Green



-Script Nodes:

-Basic nodes for performing specific actions
-Includes sequence controllers, variables, and logic gates
-Colors vary



Step 5: The storyline
It's a good idea to have a clear picture of the series of events you want to play through.
In this case, we have a simple set of objectives.
Repair the refinery
Turn on the refinery
Overload the battery
Restore power
Detect player removed ingots
Close session

Now we can use the "start" script to set up the scene.
Making the Scenario
Step 6: scripting visually

On the init event we want to set the refinery integrity, set power to off and place materials inside the cargo container once this is done we can use a complete node to close this script.

Each of these sections is connected by a sequence to make it look neat.


Don't be fooled by the name a sequence runs so fast it might as well be all at the same time.

This set of nodes will take the health of the entity and halve the value to set the health of the block. Get block health with either take current health of the maximum state depending setting of the build integrity boolean. If you want you can directly set the heath value as an integer directly into the set health node.



The set adds the components, this could be done in the scenario set when it's being built but you might want to have this as an event in the scenario so I've set this out here.


The last node added to the sequence is the complete transition


This will terminate this script section and move to the next one defined in the state machine.
To get a complete node you must drag out a connection from a node and search for “complete” in the context menu



On the dispose event we will create a new questlog called “The ultimate quest” and set the first detail task to "repair the refinery!"



The questlog is the list of tasks at the top of the screen



From the state machine, we can see the next script from "start" is "part" if you add more scripts you can use the state machine to control what order they will play.



Within the “part” script we want to use the update method to check the condition of the refinery.

Here you can see how to highlight an object by using the integrity check the highlight will deactivate once the refinery is functional


A branch allows you to stop a script from proceeding until a true/false condition is met. It is used here prior to updating the questlog, If true then proceed and update the quest to "Activate the refinery", but because the update method is run every frame we need to add a “once” script so what comes afterwards is not repeated.


This will section compare the block heath in both its current state and its potential maximum, the arithmetic node is set to compare and will output a boolean of false until the block integrity is 100%



As this part is complete the next step is to turn on the system so that to guide the player a highlight is set on the button panel.


"Button pressed" method will disable the panel highlight, then apply a large amount of damage to the battery entity finally update our questlog "Power overload look for alternative power supply".


Now onto the end script using the update method to check the grid is powered this will set the output to true and allow the branch to continue where we set quest complete.




As the last script in the state machine, it will end the scenario.

Additionally using a finished state to the line will close out the session with the option of unloading the game and rolling keen credits. Right-click and choose final then drag a connection from the “end” objective script over the final block to connect.


14 Comments
Chipstix213  [author] 24 Sep, 2023 @ 9:20am 
In the tools folder either in the mod sdk or the game installation folders
Jacksknife 24 Sep, 2023 @ 1:08am 
Small question, where do you find this scripting tool?
Sicky 23 Sep, 2023 @ 8:16pm 
ah, thanks wasn't aware of that.
Chipstix213  [author] 21 Sep, 2023 @ 10:52pm 
The sequence grows as you and more steps automatically.

Head on over to the keen discord where there are better opportunities to help out in a dedicated modding channel
Sicky 21 Sep, 2023 @ 7:48pm 
Hey! thanks for making this guide and the accompanying test scenario. And I hate that I'm going to ask this as it might be reductive to that initial comment. But would you be able to go through the basics of VST with me or refer me to some one that might be able to? I find that it only takes one session with a mentor to get the very basics down for scripting software... and that would be preferable than fumbling my way along.

If neither of these options are possible I will understand, and in that case how do I add more steps to a sequence?
Chipstix213  [author] 1 Jul, 2023 @ 12:11am 
It's tricky, if all you have done is add some grids or triggers to the same world you started with, you can copy the sandbox_0_0_0.sbs and sandbox_0_0_0.sbsb5 files.
If you've just modified voxel I think you just need to copy the corresponding vx2 file.

Anything else it might be easier starting fresh and copying the script files across instead
Dr Crow 30 Jun, 2023 @ 3:39pm 
Fantastic guide! Quick question: is there a way to modify the world after it was turned into a scenario? The scenario became separate from the imported saved world and modifying the latter will not change the scenario...
CosmicDonut 31 Oct, 2022 @ 6:09pm 
Thanks for the intro man, this is a good starter. I can tell I'm gonna have to spend a lot of time messing around with it, but it looks like there are a ton of possibilities.
Chipstix213  [author] 23 May, 2022 @ 8:45am 
Glad it's helpful
Rover House 23 May, 2022 @ 8:44am 
this is perfect for my scenario where you interact with reclaimer! thanks