Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 1.77 KB

c3.md

File metadata and controls

27 lines (18 loc) · 1.77 KB

Chapter 3: Data fields

Last chapter we left off on finding our way into some fundamentals. However, we did not code a single line yet.
To change that, let's imagine a ship in Starbase. That ship obviously needs a door of some sorts (not really but let's just assume it has one) which comes with its own set of "device fields". These fields determine the state of a device - in the case of our door one such field might determine whether the door is closed or open.

Accessing device fields

Let's say we want to change the current state from our imaginary door from closed to open. For that, we'd have to change the responsible device field (let's call it openState) from 0 to 1. So let's try the following:

SNIPPET

openState=1

Upon running that line a new local variable is added. However our original goal to change the openState device field was not achieved.

Why..?

What happens here is that we didn't address a device field at all. Instead, we created a local variable. To address a device field we need to append a colon : to the front of the field name, like so:

SNIPPET

:openState=1

Upon rerunning the code it should now change the openState of our door-device to the value you assigned it to.
We opened our door!!

Difference between local variables and device specific fields

Just like device fields, local variables are able to hold any type of value supported by YOLOL (strings and numbers). However, they do not directly affect the device like data fields. Variables are rather for temporarily saving data to use in calculations or the like. We might not need them for simple code like the one we just wrote but we'll definitely need them in later chapters.

Previous Chapter Next Chapter