# Welcome

Welcome to ComputerScience.io!

This website is for students who are interested in learning about Computer Science through Roblox :D  ComputerScience.io is written by Professor Cheng, a high school computer science teacher and adjunct professor.  He can be reached at mcheng @ kean.edu


# What is Lua?

## What is Lua?

![Source: Alexandre Nakonechnyj (Grafik-Design) und Lua-Team (PostScript-Code) / Public domain](/files/-M3xdX2zw1qa4Oe98RHr)

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode with a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

## Where does Lua come from?

![Source: Governo do Brasil / Public domain](/files/-M3xd4V1AuPWMde5BbRA)

Lua is designed, implemented, and maintained by a team at PUC-Rio, the Pontifical Catholic University of Rio de Janeiro in Brazil. &#x20;

![Source: Pontifical Catholic University of Rio de Janeiro](/files/-M4055C7oX11Sr4yNFCD)

It was designed by Roberto Lerusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo.

## What does Lua mean?

![Source: Gregory H. Revera / CC BY-SA](/files/-M3xcJ6Pchqd9oHzfe08)

"Lua" (pronounced LOO-ah) means "Moon" in Portuguese.&#x20;

##


# Design of Lua

## A Look at the Design of Lua Video

{% embed url="<https://vimeo.com/292779036>" %}

## A Look at the Design of Lua

{% embed url="<https://mags.acm.org/communications/november_2018?folio=114&pg=116#pg116>" %}
By Roberto Ierusalimschy, Luiz Henrique De Figueiredo, Waldemar Celes Communications of the ACM, November 2018, Vol. 61 No. 11, Pages 114-123 10.1145/3186277
{% endembed %}


# Luau

![](/files/-Md7xCtABDF1yVUY0Dd8)

Lua*u* (lowercase *u*, /ˈlu.aʊ/) is a fast, small, safe, gradually typed embeddable scripting language derived from Lua. It is used by Roblox game developers to write game code, as well as by Roblox engineers to implement large parts of the user-facing application code as well as portions of the editor (Roblox Studio) as plugins.

Luau is syntactically backwards-compatible with Lua 5.1 (code that is valid Lua 5.1 is also valid Luau).

Roblox has extended Lua with additional features.  The syntax is described [here](https://luau-lang.org/syntax).

{% embed url="<https://luau-lang.org/>" %}


# Decisions

## Decisions Presentation

{% embed url="<https://docs.google.com/presentation/d/1byaxAfT43SrNdcOCJ5MOQJ1cXHwKsWtICkfCIJnHrDQ/edit?usp=sharing>" %}


# Introduction

{% embed url="<https://youtu.be/VL6rYNmfrjM>" %}


# Roblox Studio

You can download and install Roblox Studio at [https://www.roblox.com/create](https://www.roblox.com/crae)

![Source: Roblox](/files/3a3zO2Vkv2Cd9653qefY)

Once you have Roblox Studio installed, open it and you'll be presented with options to create new games or edit your existing ones.  Roblox Studio is updated often and you'll notice it updating at least once a week.

## Templates

Roblox gives you a number of templates to choose from.  At the moment, the following templates are available:

* Baseplate
* Classic Baseplate
* Flat Terrain
* Village
* Castle
* Suburban
* Racing
* Pirate Island
* Western
* City
* Obby
* Starting Place
* Line Runner
* Capture the Flag
* Team/FFA Arena
* Combat
* Move It Simulator
* Mansion of Wonder

![](/files/7rL6LIGI7YYEscKK7MAq)

## Open File

You can also open Roblox Studio files by clicking on File and then Open from File.

![](/files/iX7QlTJN0VSTy1YKWkcH)

## &#x20;


# Roblox Studio Basics

## Basics of Roblox Studio

If you start building your obby above the grey baseplate, your player will just fall harmlessly onto the baseplate rather than dying when they miss their jump. That doesn’t exactly give your player the challenge you want them to have. To remove the baseplate, you’ll need to use the Explorer window.

### Explorer Window

The Explorer window is typically to the right of your workspace and lists all the objects within your game. You can use the Explorer to select and work with parts in your game, even if you can’t find them in the 3D view.

![](/files/-MHm9ucD9qyYcodDtL-W)

### Delete the Baseplate

![](/files/-MHmAxIBHE-9yXru1A2D)

Click on the Baseplate and delete.  On a PC, you can also right click or on a Mac, you can two finger tap.

### Creating a Player Start

The first thing to do when creating a game is determine where players start. The SpawnLocation is where a player appears in the world at the start of the game or after falling off a platform. Without a SpawnLocation, the player might appear somewhere randomly and fall to their doom.

![](/files/-MHmCurCH15uCxOP1zG_)


# Story Game Project

## Introduction

In the Story Game Project, words are going missing and it’s up to you to fill in the blanks!

{% embed url="<https://developer.roblox.com/assets/bltb1957a33ec3c6afb/wccVideo_final_wSound.mp4>" %}

## Writing the Story

Before coding, write the story you’ll use as the base of your game. The story can be about anything you wish.  Write 2-3 sentences for the opening paragraph.

```
Once upon a time, there was a Wise Wizz of Woo.  He had magical friends and
the name of friends are one, two, three, four, five, six, seven, eight, nine and ten.
```

## Creating Placeholders

To create a word game out of the story, delete words from the story and create placeholders for them. In the game, players will answer questions to fill in the placeholders. Start with just the first sentence.

1. In the first sentence, pick a single word to be replaced by the player such as a name, action, or a noun.
2. Replace the word with a placeholder for what type of word you’ll ask the player for.
3. Since you might end up asking the player for more than one noun or adjective, number the placeholder.

The story is now ready to turn into code!

## Open the Template

Templates are pre-made worlds that you can use as a base for your own games.

Download the template.

{% embed url="<https://drive.google.com/file/d/1tKKPm4wnKkGafFp6yYtx1GRdXI1NhfrT/view?usp=sharing>" %}

In Roblox Studio, in the top left, click File > Open from File and select the downloaded file.

![](/files/-M3nU-scpKhwX1ZiDCKM)

![](/files/-M3nUFR9HJG4cz15EMOw)

## Close Extra Windows

The first time you launch Roblox Studio, extra windows might open up that you don’t need right now. Closing the extra windows will give you more space to see what you’re doing.

1. Close all windows on the left side of Studio by clicking the ×. If you don’t see anything to close, go to the next step.
2. Leave the Explorer window on the right side open. Make Studio look like the image below.

![](/files/-M3nUW-3SvVAQbZWVS2i)

## Opening the Script

In Roblox, code is typed inside of scripts using the coding language Lua. Games often have separate scripts for each thing the game needs to do. The library template already has a script named StoryManager which you’ll add more code to for your word game.

To find the StoryManager script:

In the Explorer window, click the arrow next to **StarterGUI** to see everything beneath it.

![](/files/-M3nYebSyWnHe1EB7NyK)

Click the arrow next to **GameGUI** to expand that section.

![](/files/-M3nYqDHFUFpJB5sdhhC)

Double-click the **StoryManager** script to open it.

![](/files/-M3nZ3kz1LPeM9WTMZ-H)

## The StoryManager Script

The script already contains some of the code that’s necessary for showing the completed story to the player. All of the code you create will be typed below the dashed lines.

```lua
--Special achnowledgement @polarpanda16.

-- GLOBAL VARIABLES
local storyMaker = require(script:WaitForChild("StoryMaker"))

-- Code controlling the game
local playing = true

while playing do
	storyMaker:Reset()
	
	-- Code story between the dashes	
	-- =============================================
	
	
	
	
	
	-- =============================================
		
	-- Add the story variable between the parenthesis below 
	storyMaker:Write()
	-- Play again?
	playing = storyMaker:PlayAgain()
end
```

### Comments

Lines of code starting with `--` are **comments**. Comments are used to leave notes for yourself and other coders. They don’t change the way the program runs.

## Asking Questions

The variable you just created will be used to both ask players questions and to store their answer. The questions will show up in the middle of the player’s screen after they click on the large book at the front of the library.

## Add a Question

#### Store Info Inside the Variable <a href="#store-info-inside-the-variable" id="store-info-inside-the-variable"></a>

What’s stored inside of variables can be changed by using the `=` symbol. A variable might change many times inside of a script or as the program runs.

1.After the variable name, like `local name1`, type `=`

```lua
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
    local name1 =
```

The next step will be to ask the players a question and store their answer inside of the variable.

2\. After `=`, type `storyMaker:GetInput("Question")`. The code must be typed exactly as is, and capital letters must match.

```lua
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
	local name1 = storyMaker:GetInput("Question")
```

**storyMaker:GetInput()**

Scripts can talk to each other. This game has a second script named `storyMaker`, and inside of that is code for getting player input. The variable just made will run the code from the `storyMaker` script and then store the player’s answer.

#### String Types <a href="#string-types" id="string-types"></a>

Variables can store different types of data including small numbers, true or false values, and strings. **String type** variables are special because they can store whole sentences.

It’s easy to spot string type variables because they’re always in quotation marks `"like this"`.

* Replace `"Question"` with what you want to ask players in order to complete the next line of the story. Don’t forget to include the quotation marks (`""`).

```lua
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
    local name1 = storyMaker:GetInput("What is your favorite name?")
```

## Write the Story

## Code the First String <a href="#code-the-first-string" id="code-the-first-string"></a>

1. Make sure the playtest is stopped.
2. Go back to the script by clicking on the **StoryManager** script tab above the game editor.
3. Beneath where you typed the question, create a new variable named `story`. Make sure the variable name is **lowercase**.
4. To find the first string, go back to the original story. Circle or highlight everything before the first placeholder. If your variable happens to be in the middle of a sentence, no problem - the rest can be added later.
5. Have the `story` variable store the string like below:

```lua
local name1 = storyMaker:GetInput("What is your favorite name?")
   
local story = "In a tree on a hill lives the great wizard "
```


# API

## Part

### What is a Part <a href="#what-is-a-part" id="what-is-a-part"></a>

The Part object is a physical object. When it is in the [`Workspace`](https://developer.roblox.com/en-us/api-reference/class/Workspace), it will move and interact with other Parts. It can have bonds formed with other Parts, so that the two Parts stay in the same relative position.

Parts are the basic building blocks of any Roblox place. Commonly known as **bricks**, you’ll see these the most often of any other objects as almost every place is built out of these. It is possible to stretch a Part to very large sizes and use them for baseplates, or make them very small and use them to create cool looking [`Tool`](https://developer.roblox.com/en-us/api-reference/class/Tool).

### How can I edit a Part <a href="#how-can-i-edit-a-part" id="how-can-i-edit-a-part"></a>

The Part object can be edited using the various studio tools. It is available via either the insert menu, or the *Object Insert menu*. It can also be created using the function:

```
Instance.new("Part")
```

### How do I create different shaped Parts <a href="#how-do-i-create-different-shaped-parts" id="how-do-i-create-different-shaped-parts"></a>

Using the Mesh objects, such as [`SpecialMesh`](https://developer.roblox.com/en-us/api-reference/class/SpecialMesh), [`BlockMesh`](https://developer.roblox.com/en-us/api-reference/class/BlockMesh), or [`CylinderMesh`](https://developer.roblox.com/en-us/api-reference/class/CylinderMesh) objects you can change the shape of them. Using the [`Decal`](https://developer.roblox.com/en-us/api-reference/class/Decal) or [`Texture`](https://developer.roblox.com/en-us/api-reference/class/Texture) objects, you can place pictures on top of the bricks.

### Changing Parts using scripts <a href="#changing-parts-using-scripts" id="changing-parts-using-scripts"></a>

There are many scripting opportunities using the Part object. Many of the other scripting objects, such as [`BodyForce`](https://developer.roblox.com/en-us/api-reference/class/BodyForce) objects operate inside of a Part or other physics based objects. Editing the Part’s properties through a script can result in a lot of fun opportunities.

Reference: <https://developer.roblox.com/en-us/api-reference/class/Part>

## Model&#x20;

Models are container objects, meaning they hold objects and group objects together. They are best used to hold collections of [`BasePart`](https://developer.roblox.com/en-us/api-reference/class/BasePart)s and have a number of functions that extend their functionality.

At their most basic level, Models allow developers to group selections of [`BasePart`](https://developer.roblox.com/en-us/api-reference/class/BasePart)s together. This is particularly useful when building environments in Roblox Studio as it means the grouped parts can be moved and rotated together. When not storing collections of [`BasePart`](https://developer.roblox.com/en-us/api-reference/class/BasePart)s it is recommended that developers use the [`Folder`](https://developer.roblox.com/en-us/api-reference/class/Folder) object, as they will not benefit from the additional functionality Models provide.

To access some of the extended functionality Models provide, the [`Model.PrimaryPart`](https://developer.roblox.com/en-us/api-reference/property/Model/PrimaryPart) property needs to be set. This property points to the [`BasePart`](https://developer.roblox.com/en-us/api-reference/class/BasePart) within the Model that is to be used when moving or otherwise manipulating the model.

Models have a wide range of applications, including being used for Roblox Player Characters. They also have a number of unique behaviors that are important to keep in mind when using them:

* When a [`Humanoid`](https://developer.roblox.com/en-us/api-reference/class/Humanoid) and a [`Part`](https://developer.roblox.com/en-us/api-reference/class/Part) named “Head” are parented under a model, a name-tag GUI will appear with the name of the model.
* If a [`Part`](https://developer.roblox.com/en-us/api-reference/class/Part)’s position on the Y axis hits the [`Workspace.FallenPartsDestroyHeight`](https://developer.roblox.com/en-us/api-reference/property/Workspace/FallenPartsDestroyHeight) value, and it was the last object inside of a Model, the Model will be destroyed as well.

Reference <https://developer.roblox.com/en-us/api-reference/class/Model>


