Saturday, August 23, 2008

Professor ROBLOX: Class In Session

KidsLike.info has been reviewing various systems designed to teach kids programming, such as Scratch, Alice, Greenfoot, Python, and Java. As I've mentioned previously, Randy Pausch helped launch the Alice project as a way to "pay it forward and shape the lives of lots of future programmers.

ROBLOX offers the same potential as Alice and KidsLike.info agrees. Further, they left a comment on one of my ROBLOX-related posts asking if I could post some of my son's code in order to help other young people understand what ROBLOX code actually looks like. Great idea! I brainstormed with my son and he offered up the following short snippet of code that shows how he makes it easy to explode things within the ROBLOX world:

-- Scripts for creating, placing, and exploding bombs.

bin = script.Parent
local player = bin.Parent.Parent

-- Create a bomb where you clicked. Keep a reference to it so you can explode it later.
function onButton1Down(mouse)
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
if (player.Character.Head.Position - mouse.Hit.p).magnitude < 50 then
local P = Instance.new("Part")
P.Name = "Bomb"
P.Size = Vector3.new(1,1,1)
P.Anchored = true
P.Position = mouse.Hit.p
P.BrickColor = BrickColor.new(26)
P.Parent = player.Character

mouse.Icon = "rbxasset://textures\\GunCursor.png"
end
end

-- When you press q, explode all the bombs you created and watch all the stuff explode!
function onKeyDown(key)
key = string.lower(key)

if key == "q" then
local g = player.Character:children()
for i = 1,#g do
if g[i].Name == "Bomb" then
local a = Instance.new("Explosion")
a.Parent = game.Workspace
a.Position = g[i].Position
wait(0.1)
g[i]:Remove()
end
end
end
end

-- Bomb tool selected. Hook in my own function for ButtonDown and KeyDown.
function onSelected(mouse)
print("Action Tool Selected")
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)

mouse.KeyDown:connect(onKeyDown)
end

bin.Selected:connect(onSelected)

ROBLOX is an event-based system that leverages Lua as the programming language. In the code snippet above, my son overrides the default events (i.e. onButtonDown, onKeyDown, etc.) and plugs in his own EXPLOSIVE extensions.

The code above essentially enables you to click anywhere to plant bombs wherever you want them, and then press the 'q' key to invoke your mayhem.

Good fun...good fun. :-)

6 comments:

kids like . info said...

Hi Professor Roblox,
Thank you and your son. This is awesome! We can't wait to try it. You are way ahead of us, so it might take us awhile.

Thank you very much.

Kids like . info

And thank you for the comment on kidslike.info letting us know to come and look here.

kids like . info said...

By the way, as far as I can tell, the "they left a comment on one of my roblox related posts" links back to this page, instead of the one you intended.

Feel free to delete this if the link is corrected.

kids like . info said...

Professor Roblox,
We've been compiling a list of the best programming books for Scratch, Alice, Python, and Java.
http://kidslike.info/recommended_books_teaching_kids_programming

Have you and your son used any books for Lua?
How did he teach himself Lua?
Were there some websites that he used?

Shaun Connolly said...

ROBLOX has a complete wiki section devoted to Lua:
http://wiki.roblox.com/index.php?title=Lua_Help

He used this to learn Lua and reached out to the ROBLOX community by posting questions on the Forums. He also built relationships with some of the power users who helped him with some of his more complex scripts (i.e. moving things in 3-dimensions).

I provide links to their forums, blogs, wiki, etc, in my original post.

Anonymous said...

I feel almost as though your son is someone I play with alot. Can you tell me his username?

dale said...

The Explosion script:
can't seem to get this script to work? any help? dale.magnin@gmail.com