How To Make Glow Scripts

From Goodblox Wiki
Jump to navigationJump to search

Introduction

There are many ways to make a brick glow. This tutorial will explain the concept of making things glow using scripts.

The Reflectance Glow

First, insert a brick, in GoodBlox Studio, then Insert a script inside this brick. Open up the script, then delete the text that says "Hello World!". Then, add the following text:

while true do
	for i=1, 9, 1 do
		-- Go up
		script.Parent.Reflectance = i * .1
		wait(.1)
	end
	for i=9, 1, -1 do
		-- Go down
		script.Parent.Reflectance = i * .1
		wait(.1)
	end
end

Comments

-- Go up and -- Go down are both preceded by double hyphens. Anything preceded by double hypens are ignored by the computer. Comments can help people by describing the purpose of a section of code, but the script will work just as fine with or without the comments.

Loops

for i=1, 9, 1 do
     script.Parent.Reflectance = i * .1
     wait(.1)
end

"i=1" means that the script is making a variable, which is, a value that can change as the script progresses. In this case, "i" will start at 1, and will increase everytime the "for loop" loops. It will go to 9 (notice the next statement, ", 9"), increasing in units of 1 (or, as in the second loop, decreasing by 1) and then stop the loop.

script.Parent.Reflectance = i * .1

This is just setting a value, but with a catch: we're setting it to a variable. Variables are assigned numerical values. (Note the "* .1". That's to make it ".1" when i is 1, and ".4" when i is 4, for example. A decimal is just another way to write a fraction.


This is how the loop can be reversed:

	for i=9, 1, -1 do
		-- Go down
		script.Parent.Reflectance = i * .1
		wait(.1)
	end

The loop goes from the value of 9 to the value of 1, decreasing in units of 1 each time.

See also

How To Make A Shiny Brick

Make a Dance Floor (Helpful for inserting scripts)

Programming in Lua: the While loop

Programming in Lua: the For loop