generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

pcall

Previous Thread :: Next Thread 
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:06 AM
if pcall(function() player.Character.Torso end) then

'=' expected near 'end'
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
18 Aug 2013 11:08 AM
Lua doesn't support empty statements
Report Abuse
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:09 AM
umm Not sure what that means..
Does it mean I have to have a method or something on it?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
18 Aug 2013 11:10 AM
Well, try putting a variable by itself in a script and see what happens.
Report Abuse
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:12 AM
_>.>
Ok I get what you're saying but I though that since I can say:
if player.Character then

I would be able to say
if pcall(function() player.Character end) then

This is my first time using pcall... Could you give me an example of a successful use of pcall?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
18 Aug 2013 11:17 AM
`pcall` can be used to approximate what `try ... catch` statements do in other languages.

    function addStuff(a, b)
        return a, b;
    end

This would be fine.

    local success, err = pcall(addStuff, 3, 5);
    if success then
        print("Yay!")
    else
        print("Error: " .. err)
    end

This would not.

    local success, err = pcall(addStuff, {}, "im a string");
    if success then
        print("Yay!")
    else
        print("Error: " .. err)
    end
Report Abuse
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:20 AM
So, pcall is just to use/test code that may or may not work?

Also when you say "This would not." do you mean that the pcall would error so it would return false and would go to the else statement, or that the script would error?
Report Abuse
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:21 AM
if pcall(function(workspace.Zebra:destroy() end) then
print("Zebra exists and was destroyed")
else print("Zebra doesn't exist)


So with this i could test if the zebra exists and delete it if it does in one line?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
18 Aug 2013 11:27 AM
Yeah
Report Abuse
johnhugh is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
18 Aug 2013 11:27 AM
Thanks :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image