Community:Intro to Programming

From VRChat Wiki
Revision as of 05:28, 11 September 2024 by MMMaellon (talk | contribs)
IconOnly CL Portal.png
V · ECommunity-written content
The following was created by the community. It may contain material not directly endorsed by the VRChat team. To learn more, consider reading Contributing to the VRChat Wiki.
Tools.png
V · EThis page is a work in progress
This page is actively being worked on, information may be incomplete or out of date. You can help the VRChat Wiki by editing it.
[Reason: No reason provided.]

About this guide

Udon is a programming language for adding interactivity to VRChat worlds. UdonSharp is a tool for creating Udon scripts by writing in C#, which is the programming language most Unity games are made in. This guide aims to teach the basics of programming so that someone who has never programmed before can create their own Udon scripts with UdonSharp.

This is not meant to be a comprehensive programming guide; its aim is to just teach enough to help people create interactive VRChat worlds.

Computer Science 101

Hardware

CautionTriangle.png
Simplified Explanation Ahead
You don't need to know how CPU chips work to write code so I'm going to be simplifying all my explanations to get through it as quickly as possible.


Silicon to Transistors

Silicon is a semi-conductor -- a material that isn't a conductor and isn't an insulator, but somewhere in between. We can nudge the conductivity of silicon one way or another by mixing it with other materials (known as doping[1]) or by placing it in the electric field of a nearby charged piece of metal (known as the field effect[2]).

A transistor is a tiny microscopic device made from semi-conductors that utilize doping and the field effect to turn circuits on and off within your CPU. For example, you can dope the silicon within a transistor to make it not conductive so that it blocks the flow of electricity through a circuit. Then when you want to use that circuit, you would use the field effect to make the silicon conductive again. Here is a diagram showing how that'd work:

Diagram of a transistor using the field effect to change its conductivity. The charges in the diagram are represented with rats.

The above example shows a transistor whose default state is off, but you can also make transistors whose default state is on, meaning they only conduct electricity when there's no charge applied.

Transistors to Computers

There are a bunch of pins on the back of your CPU that plug into your motherboard. Some are input pins, and some are output. Each CPU cycle, a specific pattern of input pins lights up, opening and closing different circuits inside the CPU. The electric current then races through the CPU, eventually exiting on a specific pattern of output pins.

Closeup of the CPU pins on the back of my old AMD Ryzen 7 3800x

Let's imagine that I was a CPU manufacturer who wanted to make a computer chip that only had one function: to tell if a number was 69 or not. I have a bunch of CPU pins and two types of transistors that I can attach to the pins: type A which only opens the circuit when the pin has a electrical charge, and type B which only opens the circuit when the pin has no charge.

The binary representation for 69 is 1000101, so if I put all my transistors on the same circuit, and then arranged the type A's and type B's like ABBBABA, then I'd have a chip that detects the number 69.

It's just as easy to make a circuit that detects two numbers and outputs their sum. Repeat that for all combinations of two numbers and I have a chip that performs addition.

I can then make another circuit for performing subtraction and then have a special pin switch between which circuit is active.

Modern CPUs have billions of transistors switching between a massive amount of different circuits that all perform different actions.

Software

The input is known as the instruction and usually has two parts: the opcode and the operand. The opcode, short for operation code, tells the CPU what kind of operation to perform. The operand is the data that the opcode works with. For example, if the opcode is for adding two numbers and saving the result to a CPU register, the transistors that control the addition circuit will activate, as well as the circuit that leads to saving the output to the specified register. The operand is then routed through the pathway that just opened up.

<TODO> binary -> assembly -> code -> natural language

Compiling and Running code

<TODO>

Structure of an UdonSharp script

Namespaces

<TODO>

Classes

<TODO>

Functions

<TODO>

Variables

<TODO>

Unity SDK

Events

<TODO>

VRChat SDKs

Players

<TODO>

Coding Tutorial

<TODO>

Advanced Concepts

Networking

Optimization

<TODO>