I realize it is a bit confusing on how to use custom nodes in Vizzy at the moment, so here is a guide that will hopefully help you to get started.
There are two types of custom nodes: Custom Instructions and Custom Expressions. Custom Instructions can execute any number of instructions, run loops, change variables, etc. They are a bit like a mini program. Custom Expressions can only return a value and they cannot execute other instructions.
Right now, there is no UI to create a custom node, so you need to define it via XML. I do plan to add a UI after the winter break to make this part easier.
CUSTOM INSTRUCTIONS
Let's build a custom instruction that does a countdown. Edit your program's XML and insert this blob of XML just above the closing </Program> tag.
<Instructions>
<CustomInstruction id="9999" format="countdown from |time|" callFormat="countdown from (0)" name="Countdown" style="custom-instruction" />
</Instructions>
Now load the XML in Vizzy and notice there is a purple block on the surface.
The format
attribute above defines how this looks. The |time|
indicates it can accept an input. This will be the starting time to countdown from. Now let's build the bulk of the custom instruction by dragging blocks out from the toolbox. It should loop and countdown from the specified time to zero. Here's what I ended up with.
Now this is just the definition, so we need to be able to actually call/execute it from our program. Notice there is a new Custom Instructions panel with a new block we can use in our program.
The callFormat
attribute in the XML above defines how this looks. The (0)
indicates the block takes an input. It passes this input into the time
variable in the definition we just made. Finally, let's use this in our program:
CUSTOM EXPRESSIONS
Custom Expressions can be used to return a value. They can't execute other instructions, but they can be useful if you are often repeating the same calculations. For example, an expression that clamps a value between a min and max would be handy. Here's a definition for a clamp expression:
<CustomExpression format="clamp |x| between |min| and |max| return (0)" callFormat="clamp (0) between (1) and (2)" name="Clamp" style="custom-expression">
<Constant number="0" />
</CustomExpression>
Insert this XML blob between the starting <Expressions> tag and the closing </Expressions> tag and open your program's XML. Notice the new purple, rounded definition block on the surface and the new addition to the toolbox.
Now we can easily define what the custom expression should return by dragging out other built-in expressions from the toolbox. Hopefully, I got it right!
Now that it's defined, we can use it in our program. I threw together a simple program that just displays the result in three different test cases to ensure it is working properly.
It outputs 10, 15, and 20 in the flight scene, so it appears to be working as expected.
That's it for custom instructions and expressions. I will try and get the user interface finished so you can easily create them without having to edit XML manually.
How do i do this on Android?
@N1ghtH4wk Hi spoiler alert!! Building pretty fast
@kilobit hi kilobit
@ShreyashJadhav there's a specific block to control Activation Groups
Will you please tell me how to activate particular activation group
How do I import a program and where do I sew it from?
How can I use a condition provided as an argument?
I've already tried several possibilities but none of them work...
@zzazza this can be a misleading answer since in the first beta and in the published version some units changed
@Wings24 You can find out by yourself, it's not hard.
means that we can make an target distance detector.
Can you show an example with more than one custom expression?
@AndrewGarrison , what are the base units used for all of the variables, e.g thrust etc.
@AndrewGarrison How do I get the variable for craft attitude?
@AndrewGarrison maybe something like the subassembly folder but for custom instructions and expressions can come in handy. Doesn't really matter they don't update in all programs after changing things but can help reduce time when building things.
One custom expression I would like to have easy to access (and may even be an useful block for the stock options) is cap throttle to X twr (it's an easy thing to calculate but annoying to do it each time and may not be obvious for some users)
EDIT: To clarify, it is
min of 100 and X*100*gravity*mass/maxThrust
@DPSAircraft that's not what I asked :(
@MetalNickA We are planning to release this update this week.
@DPSAircraft Good feedback, thank you.
@pedro16797 The custom expressions and instructions must exist in the same program XML where they are being used. I would recommend creating a "library" program XML file that you can import into any craft's program. Obviously, one downside to this is that if you make a tweak to a custom node in the library's XML file, then the places where it's already been imported will not inherit the change.
@Foxman21
I play on iOS apple I don’t have a Samsung or LG phone
@AndrewGarrison is there any way to keep custom instructions and expressions in the designer and not only per craft?
When will this be on the mobile version of the game?
When’s the update for ios?
@AndrewGarrison cool thanks
@Insanity I see. I'll try to keep that in mind for the next update.
@disisto4433 Not currently. That will be available in the next update after 0.8.400.