Behavior Programming: Difference between revisions

From Desynced Wiki
mNo edit summary
mNo edit summary
Line 1: Line 1:
Herein is where you can hopefully learn about the instructions within behaviors and how they are used and hopefully you can come away with some usage context. The behavior walkthroughs listed are not designed to be feature rich and will undoubtedly be improvable, but should hold up for the task it is designed for.
In this article you can hopefully learn about the instructions within behaviors and how they are used and hopefully you can come away with some usage context. The behavior walkthroughs listed are not designed to be feature rich and will undoubtedly be improvable, but should hold up for the task it is designed for.


To prepare for the first scenario
To prepare for the first scenario

Revision as of 13:19, 19 August 2023

In this article you can hopefully learn about the instructions within behaviors and how they are used and hopefully you can come away with some usage context. The behavior walkthroughs listed are not designed to be feature rich and will undoubtedly be improvable, but should hold up for the task it is designed for.

To prepare for the first scenario

Utilizing Parameters for passing information into and out of a behavior

Registers, parameters and variables are a key element to the game and especially so for making any good use of behaviors. In short, all three are essentially one and the same: a place to store and recall information.

  • A register is the inputs and outputs of components. When you assign a Fabricator to produce Metal Bars, you are interacting with the first register. The Fabricator then assigns the second register to Metal Ore.
    • Another example is the visual register on the unit registers interface below the component registers.
  • A parameter is created from within a behavior - on the top left of the editor, you will see a - and a + sign. You can create as many or as few as you deem necessary. The main benefit of doing so is so that you can pass information into and out of a behavior without using any unit registers.
  • A variable is exclusively for use inside a behavior and it serves as a quicker way of creating information storage that is visually recognizable at a glance. If you have any instruction with an output, you can create a new variable - they are alphanumeric, so the first is A, then B, etc.
Components and their corresponding instruction analogs

One objective of the game is to enable the user to choose whether or not they wish to interact with behaviors. It isn't strictly necessary to enjoy or progress through the game to do so, but you're here now so you've made your choice. The game provides analogs of components in the form of instructions within behaviors. One of these is the Portable Radar and another is the Signal Reader.

The two are often used in combination - for example:

  • You can find a Construction using a Portable Radar with the filter:construction. The result can be linked into a Signal Reader to automate getting the signal.
  • A building under construction has a requirement of materials to be delivered. What is useful in this case is that it stores required materials the signal register. Using a Signal Reader or its analog, the Read Signal instruction, you can obtain the stored signal value.
Creating a Construction Worker

One day you may want to create a building far out in the distance and ask yourself why the bots don't bother tending to it. Simply put, its not in the logistics network and so you will have to perform manual operations or adapt.

Requirements

For this next part you will need: a Portable Radar a Worker and a Behavior Controller.

The Radar
  1. Find and introduce the Radar instruction and connect it to the starting node
  2. Input a filter for Construction into the Radar instruction - it should be under the Information section
  3. Set the Result parameter to a new variable:A
The Signal Reader
  1. Find and introduce the Read Signal instruction - attaching it to the top node of the Radar instruction - we will ignore the No Result branch of the Radar instruction
  2. Input the result variable:A into the Unit parameter of Read Signal
  3. Write the Result into a new variable:B

What we have now is a two-instruction behavior that finds a construction in range and acquires its signal which is an item required for the construction to be completed. What we must do next once we have this information is to automate the acquisition and delivery of those items to the unit and the construction in question.

Going Home
  1. Find and introduce the Move Unit instruction - we will want to be able to specify where the bot needs to return to to await items
  2. Create a parameter within the behavior editor ( - and + up the top left corner) and click on its name and label it as "Home Location"
  3. Click on the Target parameter of Move Unit or drag in the first parameter(P1)
Requesting the items
  1. Find and introduce the Request Item instruction - we are going to ask the logistic network to deliver what the construction requires
  2. Input the variable:B into the Item parameter

We have requested an item from the network, but we will want to wait until it is in the Worker's inventory before we return to deliver the items. We need to know what is in our inventory and then evaluate what action to take.

Counting
  1. Find and introduce the Count Items instruction
  2. Set Item to variable:B and set Result to a new variable:C
Evaluating
  1. Find and introduce the Compare Number instruction
  2. Set Value to variable:C
  3. Set Compare to variable:B
  4. Link the If Smaller node to the start of the Request Item instruction

What this means is that if we have less than the desired amount, the bot will stay put until the items are delivered. We can now proceed

Dropping off the items
  1. Find and introduce Drop Off Items to the If Equal node of the Compare Number instruction
  2. Set variable:A as the destination

You're done! Name your behavior, give it a description and make sure to save it to the Library down the bottom right.

Setting it up
  1. Apply the behavior to a Behavior Controller on your Worker and also equip a Portable Radar
  2. Because you added an additional parameter to your Behavior Controller, you will note that it has its own register. Set this to a location within your power grid that you deem a suitable place to wait for materials to be delivered to the Worker
  3. Press the Start behavior button to the right of your unit's inventory slots
  4. Place a building somewhere off in the distance and then task your Worker to move somewhere near it - the radar will do the rest

Sit back and watch


Other potential walkthroughs

Taking volunteers to write short guides on putting together a few simple behaviors.

Try not to add layers of complexity - creating a guide for something that can be improved upon will allow the student to reinforce the existing knowledge you have given them.

We need roughly 5 good examples

Good subjects may be:

Obtaining and utilizing a Signal Reader or Read Signal for item delivery or mining

Using Compare Number to determine outcomes