Only this pageAll pages
Powered by GitBook
1 of 12

ComputerScience.io

Loading...

Lua Language

Loading...

Loading...

Loading...

Loading...

Roblox Studio

Loading...

Loading...

Loading...

Loading...

Loading...

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

Design of Lua

A Look at the Design of Lua Video

A Look at the Design of Lua

Luau

Luau (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.

What is Lua?

What is Lua?

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?

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

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

What does Lua mean?

"Lua" (pronounced LOO-ah) means "Moon" in Portuguese.

Source: Alexandre Nakonechnyj (Grafik-Design) und Lua-Team (PostScript-Code) / Public domain
Source: Governo do Brasil / Public domain
Source: Pontifical Catholic University of Rio de Janeiro
Source: Gregory H. Revera / CC BY-SA

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.

Delete the Baseplate

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.

Decisions

Decisions Presentation

Roblox Studio

You can download and install Roblox Studio at https://www.roblox.com/create

Source: Roblox

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

Open File

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

API

Part

What is a Part

The Part object is a physical object. When it is in the 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 .

How can I edit a Part

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:

How do I create different shaped Parts

Using the Mesh objects, such as , , or objects you can change the shape of them. Using the or objects, you can place pictures on top of the bricks.

Changing Parts using scripts

There are many scripting opportunities using the Part object. Many of the other scripting objects, such as 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:

Model

Models are container objects, meaning they hold objects and group objects together. They are best used to hold collections of s and have a number of functions that extend their functionality.

At their most basic level, Models allow developers to group selections of 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 s it is recommended that developers use the object, as they will not benefit from the additional functionality Models provide.

To access some of the extended functionality Models provide, the property needs to be set. This property points to the 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 and a named “Head” are parented under a model, a name-tag GUI will appear with the name of the model.

  • If a ’s position on the Y axis hits the value, and it was the last object inside of a Model, the Model will be destroyed as well.

Reference

Introduction

Tool
SpecialMesh
BlockMesh
CylinderMesh
Decal
Texture
BodyForce
https://developer.roblox.com/en-us/api-reference/class/Part
BasePart
BasePart
BasePart
Folder
Model.PrimaryPart
BasePart
Humanoid
Part
Part
Workspace.FallenPartsDestroyHeight
https://developer.roblox.com/en-us/api-reference/class/Model
Instance.new("Part")

Story Game Project

Introduction

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

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.

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.

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

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.

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.

Click the arrow next to GameGUI to expand that section.

Double-click the StoryManager script to open it.

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.

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

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 =

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.

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

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 ("").

Write the Story

Code the First String

  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.

LuauLuau
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.
  • Have the story variable store the string like below:

  • 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.
    --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
    while playing do
        storyMaker:Reset()
     
        -- Code story between the dashes	
        -- =============================================
     
        local name1 =
    while playing do
        storyMaker:Reset()
     
        -- Code story between the dashes	
        -- =============================================
     
    	local name1 = storyMaker:GetInput("Question")
    while playing do
        storyMaker:Reset()
     
        -- Code story between the dashes	
        -- =============================================
     
        local name1 = storyMaker:GetInput("What is your favorite name?")
    local name1 = storyMaker:GetInput("What is your favorite name?")
       
    local story = "In a tree on a hill lives the great wizard "
    Logo
    https://developer.roblox.com/assets/bltb1957a33ec3c6afb/wccVideo_final_wSound.mp4developer.roblox.com
    Logo
    Story_Games_Template.rbxlGoogle Docs
    Logo
    https://mags.acm.org/communications/november_2018?folio=114&pg=116#pg116mags.acm.org
    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