Instructional Comments in my code for "Functions 2: Instances and Particles" from the Intro to Coding

  • As I go on my journey to learning how to program, I am trying my hand at helping others like me understand “what” is happening in the code. I’ve taken the code examples provided in the Roblox Education Hub, specifically the Intro to Coding. I began expanding the lessons to include additional information that I found helpful when I was trying to wrap my head around the concepts. The code below is for the Functions 2: Instances and Particles
  • I was hoping to have experienced programmers check to see if my terminology, logic,processes are correct. In this code specifically, I know there are some assumptions made because this is part 7 of the series. It wasn’t until I was commenting on my code that I decided to take this on. I’d be looking to go back to part 1 and do the same thing.
-- This script removes the Fire object from the part: "FirePart" and adds the ParticleEmitter object

--[[ NOTE:  Roblox and Lua recommend using camelCase notation when defining function and variable names, meaning
the first letter of the first word is lower-case, while the first letter of every other word is upper-case.
Example:  thisIsCamelCase, soIsThis, and this.
Object/Instance names are in PascalCase, meaning the first letter of each word in the object/instance name is upper-case.
Example:  ThisIsPascalCase, SoIsThis, and This.
This is only semantics (and good pratice). It doesn't actually impact anything in the code below.  
I could have named the Part "mypart" and named the variable "MYVariable; I didn't because it is poor practice.
Given that the code below uses the same words FirePart and firePart for the object/Part and variable names
this might be confusing.  If you are trying to reduce confusion, rename the Part and variable names as you'd like. ]]--  

--[[ Read assignment statements right-to-left.  The statement on the right-hand side of the assignment operator (=)
is performed first and the resulting value is assigned to the variable on the left side of the assignment operator: ]]--

local firePart = script.Parent
--[[ This statement returns the Parent property value of the script object (meaning this script file in which we're working)
When this script file was created, it was placed beneath FirePart object in Explorer, so the script.Parent statement returns "FirePart".
The value returned, "FirePart", is then assigned to the local variable: "firePart".
What the local firePart = script.Parent statement allows us to do is use this script with other parts, since we aren't referring to the 
part name directly.  If we had said local firePart = game.Workspace.FirePart.Parent, the script would only work with a Part named "FirePart". ]]--

-- If you want to see this in action, enable the print() statement, below:

-- Create local function called "stopFire":
local function stopFire()
	print("Starting stopFire() function...")
	-- Wait 10 seconds before destroying the Fire object
	--[[ This statement resolves the firePart variable name to its value: FirePart (the Part).  The first .Fire property specifies FirePart's child object, Fire.  The colon (:) indicates the built-in :Destroy() method of the Fire object  
	This essentially says: "return the value in the variable firePart, which is the Part itself (FirePart).  Then, for the child object named Fire, execute its built-in Destroy() method.
	This method deletes the Fire object from the workspace.  At this time, you can watch the Fire object disappear from the Explorer menu.
	print("Fire has been destroyed.")
	-- Wait 5 seconds before creating the ParticleEmitter object as a child of the FirePart part
	print("Creating new 'ParticleEmitter' instance...")

	local spark ="ParticleEmitter")
    --[[ Create a new instance of the ParticleEmitter object and assign it to the local variable "spark". is a built-in function for creating objects.  The object created, however, must exist in Roblox Studio ObjectBrowser.
	In this case the object "ParticleEmitter" was chosen, so the literal object "ParticleEmitter" is passed to the function, which
	creates the object.  This only creates the instance but doesn't "put" it anywhere; that will happen below. ]]--
	spark.Parent = firePart
    --[[ Get the value of the variable: firePart (Remember from the steps above, firePart stores the the name of the Part (FirePart). 
	-- Assign the value (FirePart) as the value for the Parent property of the new ParticleEmitter object (spark).
	-- By assigning the parent property to the object, the new ParticleEmitter object (spark) will be a child of the FirePart Part. ]]--

--[[NOTE:  When the script runs, watch Explorer in Roblox Studio.  You can watch the Fire object disappear and the new ParticleEmitter object appear.  
	You may need to change the wait() values to give yourself time to expand the Explorer menu to the FirePart Part ]]--