# Variables in Script

## **Basics**

After creating the script, it became your component. And in this component (further I will keep in mind about the linked script) you can create parameters and variables. Often all types of variables in C# can be used, as well as some non-standard types such as **GameObject**. All of them will be displayed in the inspector and in most cases they can be changed.

```csharp
using Force;

public class Player : MonoScript {

	public string name;
	public int age;

	// Runs when scene starts to play.
	public void OnStart() {
		Debug.Log("Hello! Im " + name + ", and my age is " + age);
	}
}
```

This code creates an editable fields in the **Inspector** labelled “Name” and "Age".

<div align="left"><figure><img src="https://2773422523-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuytHSSE0uhny7g4jsNpY%2Fuploads%2FbLAhDoewJ8tvk3okRwwm%2Fimage.png?alt=media&#x26;token=650f9d64-3609-4e39-a610-cedf58028d23" alt=""><figcaption><p>Name and Age fields from script</p></figcaption></figure></div>

In the inspector, you can edit variables. For a string, we enter the name **Danil**, and for a number, we enter **20** as the age. The names of variables to show in the inspector will format it a little, for example, making the first character uppercase or removing unnecessary characters like \_.

<div align="left"><figure><img src="https://2773422523-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuytHSSE0uhny7g4jsNpY%2Fuploads%2Fu4pcSGVY8rzoAhSNZvmO%2Fimage.png?alt=media&#x26;token=41eb944e-7d87-4705-80aa-302a2faf7f5f" alt=""><figcaption><p>Test the script</p></figcaption></figure></div>

**Note:** In order for a variable to be visible in the inspector, it must be declared as public, as well as for C#.

Force will actually let you change the value of a script’s variables in runtime. This is very useful for changes directly without having to stop and restart. When gameplay ends, the values of the variables will be reset to whatever they were before you pressed Play.

### Attributes

You can hide or show in inspector the field for special cases. For that you need to use attribute class on the field **ShowInInspector.**

```csharp
using Force;

public class Player : MonoScript {
	[ShowInInspector()]
	string name;
	public int age;
}
```

In this case field `name` will be visible in Inspector even if it private or protected or have default access modifier. This very usefull when you need to have yours variable be hidden or private from others, but visible in Inspector.

Also you can disable field for editing in Inspector using another class attribute **DisableInInspector**.

```csharp
using Force;

public class Player : MonoScript {
	public string name;
	[DisableInInspector()]
	public int age;
}
```

In second example field `age` will be only read only and not editable from Inspector.

### Properties

C# has another type of variables to declare along with fields is **properties**. Generally speaking im firstly discover its existence only now when starting to improving **Force** scripting engine.

So **Force** itself starting to support them, you can declare it in the script, but only illumination for now that they will not display in **Inspector**. So you need declare normal field first and then use it in property for getter or setter.

<pre class="language-csharp"><code class="lang-csharp">using Force;

<strong>public class Player : MonoScript {
</strong><strong>	
</strong><strong>	public string propertyField;
</strong><strong>	public string Property { get { return propertyField; } set { propertyField = value; } }
</strong>}
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://danil-dukhovenko.gitbook.io/force/force-editor/scripting/variables-in-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
