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
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 18 Aug 2013 11:08 AM |
| Lua doesn't support empty statements |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
| |
|
johnhugh
|
  |
| Joined: 26 Mar 2009 |
| Total Posts: 1971 |
|
| |
|