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
 

Re: ErrorHandler v2

Previous Thread :: Next Thread 
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 09:10 PM
It is a simple error handler class, and easy to use. I put an example at the bottom of the script.

ErrorHandler = {}

ErrorHandler.New = function(self)
local Scripts = { }
Scripts.Errored = false

Scripts.SyntaxCheck = function(self, Source, HandlerName)
Source = Source or "print 'Hello World!'"
HandlerName = HandlerName or "ErrorHandler"

local Boolean, Output = loadstring(Source, HandlerName)

if not Boolean then
self.Errored = true
return Boolean, Output

end
end

Scripts.FullCheck = function(self, Source, HandlerName)
Source = Source or "print 'Hello World!'"
HandlerName = HandlerName or "ErrorHandler"

local Function, Error = loadstring(Source, HandlerName)

if not Function then
return Error
end

if type(Function) == "function" then
local Check = coroutine.create(Source)

while not self:HasErrored() do
if coroutine.status(Check) == "dead" then break end
local Boolean, Output = coroutine.resume(Check)

if not Boolean then
return Output

elseif coroutine.status(Check) == "suspended" then
if coroutine.running() == Check then
coroutine.yield()
end
wait()

else
break

end
end
end
end

Scripts.HasErrored = function(self)
return self.Errored
end

return Scripts
end

And heres the quick example:

local Handler = ErrorHandler:New()
local Function, Error = Handler:SyntaxCheck("Check This For Errors()", "Handler")

if not Function then
print(Error) -- Prints the syntax errors
end

if type(Function) == "function" then
local Boolean, Output = Handler:FullCheck(Function, "NewHandler")
-- This will wait until it errors, so if you want your script to keep running, use coroutine.

if not Boolean then
print(Output)
end
end
Report Abuse
MrLisawsome is not online. MrLisawsome
Joined: 18 Jan 2010
Total Posts: 3606
28 Oct 2011 09:54 PM
O.M.G! Can you use this to get output in Online mode?
Report Abuse
IL0LD is not online. IL0LD
Joined: 04 Sep 2011
Total Posts: 37
28 Oct 2011 09:58 PM
Well how would you put the broken script in?
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:17 PM
Sorry, forgot to reply :P

@Mr
Yes! That's the magic of it!

@IL0LD
Well, you use this:

ScriptSource = [[ Put source here ]]

local NewHandler = ErrorHandler:New()
local RanSuccessfully, Errors = NewHandler:FullCheck(ScriptSource)

if RanSuccessfully == nil then
local message = Instance.new("Message", Workspace)
message.Text = Errors
end


P.S.
This means, You can make a script, and get any errors IN-GAME!
Report Abuse
aboy5643a is not online. aboy5643a
Joined: 20 Nov 2010
Total Posts: 2785
28 Oct 2011 10:19 PM
ErrorHandler.New() == ErrorHandler:New() ???

Since when...
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:24 PM
Oh sorry, i meant:

local RanSuccessfully, Errors = NewHandler:FullCheck(function() loadstring(ScriptSource)() end)
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:26 PM
@aboy

Learn classes, The variable 'self' is why you can say:

Workspace.Part.Remove(Workspace.Part)
and
Workspace.Part:Remove()

Because of the variable 'self', which is automatically called with colens.
Report Abuse
aboy5643a is not online. aboy5643a
Joined: 20 Nov 2010
Total Posts: 2785
28 Oct 2011 10:29 PM
Ummm...

Function Version:
Remove(script.Parent)

Method Version:
script.Parent:Remove()

The Method just puts the object in front as the first argument... Your logic doesn't conform to that...
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:32 PM
Would you like to try it? Go into solo, make a script with this source:

Workspace.Remove(Workspace[Some part name])

It works. Wanna know how I know? Because I've tested it ;D
Report Abuse
aboy5643a is not online. aboy5643a
Joined: 20 Nov 2010
Total Posts: 2785
28 Oct 2011 10:34 PM
I'm not saying it doesn't... Your structure just doesn't make logical syntax sense.

Table = {}
Table.func = function(arg) print(arg) end

Table.func("Hello, world!")
Table:func("Hello, world!")

It doesn't work like that... Because you're calling the method with Table as the first argument.
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:36 PM
Again, you didn't check the first variable 'self'. When you use a colen, it automaticly fills in the variable 'self' to that table/object/userdata. If you DON'T use a a colen, you have to manually fill it in. Which you failed to do.
Report Abuse
aboy5643a is not online. aboy5643a
Joined: 20 Nov 2010
Total Posts: 2785
28 Oct 2011 10:37 PM
You're explaining this horribly .___. Please use a 5-10 line code example of this that WORKS...

A method calls the function with the first argument as the object that the method is being called on.

Remove(script.Parent) == script.Parent:Remove()

See how that works???
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
28 Oct 2011 10:39 PM
You are saying Remove is a function though... like you would have:

function Remove(class)
class:Remove()
end


But it would actually be:

script.Parent.Remove(script.Parent)

And the example I gave does work...
Report Abuse
GoldenUrg is not online. GoldenUrg
Joined: 23 Aug 2009
Total Posts: 6428
28 Oct 2011 11:39 PM
Method/function equivalence:

local obj = {}

function obj:method( arg1 )
print( self, arg1 )
end

function obj.func( arg1, arg2 )
print( arg1, arg2 )
end

obj.func( obj, "abc" )
obj:func( "abc" )
obj:method( "abc" )
obj.method( obj, "abc" )

Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
29 Oct 2011 12:58 AM
[ Content Deleted ]
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