June 30th 2008

Scripting With Telamon: Debugging

Howdy! Today’s article is for Roblox power users who want to learn how to develop scripts in Roblox. This is not a programming language tutorial - I will assume you know enough about Lua to look at a piece of code and guess at what it does. Rather I am going to teach you how to deal with buggy scripts and show how to debug them. Debugging in general is a mystical art - I use the word "art", which is the product of innate creative forces, in contrast to "science", which can be dissected, reduced, and taught. We’ve built some tools into Roblox Studio to help you though.

Part 1 - Mission Statement

We’re going to build a secret door. An easy way to make a secret door is to make a brick and set its CanCollide property to false. Anyone can them walk through such a brick. No. Our secret door is going to be special. It’s eventually going to guard the treasure room in my castle and it’s only going to let approved members of the Pirate Army through (Arrrrr!). Clearly we need some scripting here, me hearties.

Part 2 - Build From Simpler Pieces

When I’m making a complicated script, I try to test it as I go along. I’ve seen a lot of people in intro programming classes try to write all their code at once and then test it. This is about the most painful way to write code. Don’t do it. Instead, write the shortest bit of code that you can test. Test it. If it works, add some more stuff. Then test it. If something broke, you know where to start looking.

A more simple version of the door we want to make is a door that just turns transparent whenever anything touches it.

simpledoor1.pngGo ahead and open up Roblox Studio. Create a simple test level, like the one pictured. In my level, the first test door is red. Use the Insert -> Object menu to insert a script under your test door (when the dialog box pops up, type the word "Script"). Do yourself a favor and give the script a descriptive name like "DoorScript".

Part 3 - Power Tools

Ok, time to break out the power tools. If you have been scripting without these, I feel sorry for you. There are two that I will talk about today: the Output window and the Command toolbar. The first is by far the most useful, so I will focus on it.

To bring up the Output window, use the View -> Output menu option. This is add a window pane to the bottom of your screen. This window will show the output from your scripts while they are running. If your script has an error in it, the error will be printed here along with the line number telling you where the script broke. Let’s look at both of these right now. In your new script, paste the following code:

print("Hello world!")

for i=1,10 do
print(i)
end

script.ThisPropertyDoesNotExist = 6

As you can probably tell, this script prints "Hello world!", spits out the numbers 1 to 10 and then crashes on an error. If you press the Run button in Studio, you can see this. The output will look like this:

Tue Feb 13 15:56:07 2007 - Script Heap Stats: Max Size = 21945 bytes, Max Count = 401 blocks
Hello world!
1
2
3
4
5
6
7
8
9
10
Tue Feb 13 15:56:16 2007 - ThisPropertyDoesNotExist is not a valid member of Script - =Workspace.Script, line 7: (null)

This is telling us that line 7 of our script is bad, which is something we already knew. However, in a more complicated script, it can be very helpful to print out stuff as the script is running so that you can see where things are going wrong. It may seem obvious once I’ve said it, but if something is broken with your script, start printing stuff out - rare is the bug that will not succumb to this level of scrutiny. I once wrote an entire operating system, using only printf to debug it.

commandtoolbar.pngI started programming when I was in 2nd grade and a popular language to learn back then was something called QBASIC - some of you may know it. One feature of the QBASIC programming environment was something called the Immediate Window, which you could type code into and immediately see it execute. On occasion this can be helpful to debug a script while it is running. However, this is more for advanced users. You can bring up Roblox Studio’s equivalent of the Immediate Window by using the View -> Toolbars -> Command menu option to bring up the Command Toolbar. You can type code into this at any time and run it. For example, if you wanted to, you could type:

game.Workspace.Door.Position = Vector3.new(0,100,0)

And if you have a part named "Door" in your level, it will be immediately teleported to (0, 100 ,0) while the game is running. This is kindof arcane, but I mention it because I have found the Command Toolbar useful on occasion.

Part 4 - Simple Door Script

Here it is:

print("Simple Secret Door Script Loaded")

Door = script.Parent

function onTouched(hit)
 
  print("Door Hit")
  Door.Transparency = .5
  wait(5)
  Door.Transparency = 0

end

connection = Door.Touched:connect(onTouched)

If you have ever seriously tried to learn lua scripting for Roblox, you have looked at some Roblox scripts. The code for listening to a Touch event should look familiar. Basically I have wired up the Part.Touched event to call the onTouched function whenever the part is touched by another part. When this happens, the door will turn semi-transparent for 5 seconds. Add this to your Door script, save your map, and try it. If you touch or shoot the door, you will see a nice effect. If you have the Output Window up, you will also see a "Door Hit" message printed whenever the door is touched. If you did not see this message, you would know that the onTouch function was not being called and that you had not wired up the event handler correctly.

Part 5 - A More Complicated Door

Like I said, this is not a tutorial on actually writing code, only debugging it. So here is the finished script:

print("Advanced SpecialDoor Script loaded")

— list of account names allowed to go through the door.
permission = { "Telamon", "PirateArmy", "CaptainMorgan", "SilverShanks", "JackRackam" }
Door = script.Parent

function checkOkToLetIn(name)
for i = 1,#permission do
  — convert strings to all upper case, otherwise we will let in
  — "Telamon" but not "telamon" or "tELAMON"
  if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end

function onTouched(hit)
  print("Door Hit")
  local human = hit.Parent.FindFirstChild("Humanoid")
  if (human ~= nil ) then
   — a human has touched this door!
   print("Human touched door")
   — test the human’s name against the permission list
   if (checkOkToLetIn(human.Parent.Name)) then
    print("Human passed test")
    Door.Transparency = .5
    Door.CanCollide = false
    wait(7)
    Door.CanCollide = true
    Door.Transparency = 0
   end
  end

end

connection = Door.Touched:connect(onTouched)

It has one bug in it. Without using the Output Window, the only thing you will be able to tell is that the script is not working. With the Output Window, the problem becomes obvious:

Advanced SpecialDoor Script loaded
Simple Secret Door Script Loaded
Door Hit
Tue Feb 13 16:44:19 2007 - Workspace.YellowDoor.DoorScript2:18: bad argument #1 to ‘findFirstChild’ (Instance expected, got string) -

Since the script prints out "Door Hit", but not "Human touched door", we know the problem is somewhere in line 18 or 19 of the code. The Output window tells us that there is a problem on line 18 - FindFirstChild is failing. Ah! That is because in Lua methods are invoked using a colon (:) instead of a dot (.) (all other languages of consequence use dots for this - curse the inventors of Lua!) Change the line 18 to be:

local human = hit.Parent:FindFirstChild("Humanoid")

simpledoor3.pngAnd you have a working secret door that can be programmed to only let in your friends. To see it in action, check out SpecialDoor’s Place. If you are a new scripter and you are looking for some projects to work on, here are some easy adaptations of this script that you could do:

 

  1. Make the door let in everyone except those people who are on a blacklist (this is the opposite of the current door).
  2. Make the door flash different colors while it is open.
  3. Make the door heal you as you walk through it.

- Telamon

AddThis Social Bookmark Button

June 24th 2008

Action Adventure Movie Contest Update

GoldenRobloxianRevealing the Golden Robloxian!  

This hat is the prize for this movie contest. Isn’t it majestic?

Read how to enter in the official contest post.

Deadline

Our Staff have already started watching the videos and are finding some really great stuff. Check out the latest videos entered. You guys are awesome!

Remember, if your video is longer than 3 minutes the staff may not watch past there - but a movie over 3 minutes still can win!

We have a lot of movies to see. So keep it interesting! The contest Closes Sunday June 29 at 6pm Pacific time (9pm Eastern). All videos must be posted by this time.

Prizes!

Two ways to win this hat!

1. There will be 5 Best Motion Picture winners for this event. There is no ranking among the five. All of them are winners!  “Production Teams” are welcome (up to three users) – all listed members of the team will win the Award Hat, and the three production members get $R 1000. A production member is someone like the director, writer and camera person.

2. From among all the movies the staff will also pick winners for special categories. The winners will receive the Award Hat and $R 1000 each. In order to win the username must be listed in the YouTube movie’s information by the person who posted the video.
Categories:
Best Actor/Actress (three of these will be chosen), Best Soundtrack, Best Camera Work, Best Costumes, Best Set Design and Best Special Effects.

There is still plenty of time to make a great movie! Talk about it and look for helpers on our ROBLOXiwood forum!

-ReeseMcBlox

AddThis Social Bookmark Button

June 20th 2008

Want to earn R$ 20,000 for doing almost nothing?

No, this isn’t a pyramid scheme or real estate scam. Roblox wants to hire a Web Developer and a Graphics & Game Guru and we want a Robloxian to recommend someone. Check out the job descriptions on the jobs section of roblox.com and see if you know anyone who would be a good fit for the positions. If you recommend someone for a position, and Roblox decides to hire your dad, friend, work colleague, grandma, or whomever else you recommend, you earn 20,000 Robux. You can finally afford that white top hat you’ve had your eye on.

But wait, there’s more! If you recommend people for both jobs, and we hire both of them, you get 40,000 Robux! Remember, you only get the Robux if we actually hire the person that you recommend, so make sure your recommendations are qualified and plentiful.

I know what you’re thinking…this sounds great, but how do I get credit for recommending a candidate? It’s simple. Just convince the potential hire to apply and have the person you’re recommending include your username in their cover letter. Happy hunting!

-BrightEyes

AddThis Social Bookmark Button

June 14th 2008

Action Adventure Movie Contest

Introducing ROBLOXiwood - Action Adventure Movie Contest #1!

ROBLOXiwood is open for business!  We’re having a movie contest to celebrate. The theme is Action and Adventure. Be sure to read all the guidelines below to make sure your YouTube movie gets entered.

An Action Adventure movie is one that has a thrills, chills, and a good story. The characters have to get into some sort of trouble and then get themselves out or be saved.  Your movie can be an original work or a scene from one of your favorite “real” movies.

Prizes!

Two ways to win!

Oscar 1. There will be 5 Best Motion Picture winners for this event. There is no ranking among the five. All of them are winners!  “Production Teams” are welcome (up to three users) – all listed members of the team will win the Award Hat, and the three production members get $R 1000.

2. From among all the movies the staff will also pick winners for special categories. The winners will receive the Award Hat and $R 1000 each. In order to win the username must be listed in the YouTube movie’s information by the person who posted the video.
Categories: 
Best Actor/Actress (three of these will be chosen), Best Soundtrack, Best Camera Work, Best Costumes, Best Set Design and Best Special Effects.

Rules

1. Create an Action Adventure ROBLOX video. All entries must be a movie/video. You can learn how to make Roblox movies from our tutorial.

2. Please make all videos suitable for viewing by kids, grandmas, school teachers, and your next door neighbor. No profanity or inappropriate images. Any video that breaks the standard ROBLOX rules will not be able to win.

3. Videos should be between 30 seconds and 3 minutes long.  Keep it short so the action doesn’t get lost in long scenes. Most of the footage should be ROBLOX related.

4. On your video page put the following information.
a. Usernames of team, Link to ROBLOX - http://www.roblox.com
b. Tags - This time we want you to use tons of tags!
    * You must put “ROBLOX” and “june-action”
    * Describe your video with three or four words
    * If you are taking a scene from a real movie, include the movie name –       otherwise, put the name of a movie that’s like yours
    * Include the names of your favorite building and modeling toys
    * Describe ROBLOX in three or four words
GO CRAZY WITH THE TAGS! Example:  ROBLOX june-action giant spider chase King Kong erector knex lego fun kids online world  

5. Contest Closes Sunday June 29 at 6pm Pacific time (9pm Eastern). All videos must be posted by this time.

6. There is no rule six!

How To Win

The winners will be chosen by the ROBLOX Team who will search for videos with all the right things. Videos must have been uploaded since the contest started (no old videos!), must have the ROBLOX link and june-action tags (and other tags), and must have your username. Most of all they must have Action and Adventure! This contest is subjective to the Team’s opinion. Not everyone will agree that your video is a winner, but we hope it is!

Extra:

Feel free to talk about your video on the new ROBLOXiwood forums and link to it.

Google videos will not be accepted. Only videos on YouTube will count for this event.

You can work in Production Teams OF UP TO 3 PEOPLE. In addition, you can list other team members for costumes, special effects, set design, acting…  List these team members on your credits. All members of a Best Picture winning team will get the Award Hat. All the team’s names must be listed on the YouTube video information.

Your movie can be longer than 3 minutes but the Staff does not have to watch the whole thing. Shorter is better!

Winners and prizes will be announced within a week of the contest close.

I can’t wait to see the exciting things you guys create!

-ReeseMcBlox

AddThis Social Bookmark Button

June 10th 2008

Funny Movie Contest Winners

The ROBLOX Staff has finally picked the winners for this contest. Yay! After much debate we decided to have 8 winning entries instead of 5. It was very hard to narrow down the choices and we just couldn’t leave some of these out.

In no particular order, the winning entries are…

Max & Bob Visit Robloxia by maxxz
Stfcrb’s Fun Time 2 by Stfcrb
NoobName Show by NoobName, Wirodeu and hugeflare
Roblox Christmas at Ground Zero by Stickmasterluke
Indiana Legocat5 And The Holy Bob by legocat5
Roblox: The Bloxxer Bunch by CobraStrike4
ROBLOX - May-Funny by Johnny2008 and Acbc
Top 10 ways to die in Roblox by Are92, Are14 and Minilandstan

Watch all the videos in this player!

Or click this link to see them all on my YouTube profile page.

Each of the players listed above will receive the video contest exclusive Security Camera hat and $R 300 split among their team. Winning video contests is the only way to get the hat. Are you bummed you did a lot of work and didn’t win? Well give it a try next time! Stay tuned for more exciting video contests to come.

-ReeseMcBlox

AddThis Social Bookmark Button

Next Page »