Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
xpcall failed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
xpcall failed
14-02-2015, 04:42 PM,
#1
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
xpcall failed
Hey,

I have all my functions inside xpcall for debug.

local Result = xpcall(broadcastMessage(Type, Message, ply),function(Error) return end)
saveError(Result)

I added few errors inside broadcastMessage for debug.

Doesn't seem to work:
sv: SFConfusedtarfall/ENCOM_mainframe.txt:98: bad key to string index (number expected, got string)
sv: SFConfusedtarfall/ENCOM_mainframe.txt:105: attempt to index global 'cht' (a nil value)

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
14-02-2015, 04:48 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: xpcall failed[BUG]
You're calling broadcastMessage, which returns presumably nothing, which means you then pass nil to xpcall.

xpcall then calls nil because that's what the function call returned.

This is what it should be:
local function ErrorHandler( Error )
print( "Oh noes! An error:", Error )
end
local Result = xpcall( broadcastMessage, ErrorHandler, Type, Message, ply )

Can you see why yours didn't work now?
Find
Reply
14-02-2015, 04:53 PM,
#3
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: xpcall failed
(14-02-2015, 04:48 PM)Person8880 Wrote: You're calling broadcastMessage, which returns presumably nothing, which means you then pass nil to xpcall.

xpcall then calls nil because that's what the function call returned.

This is what it should be:
local function ErrorHandler( Error )
print( "Oh noes! An error:", Error )
end
local Result = xpcall( broadcastMessage, ErrorHandler, Type, Message, ply )

Can you see why yours didn't work now?

Should my line crash the whole chip?

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
14-02-2015, 04:53 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: xpcall failed
Of course, xpcall can't catch something before it's even received its arguments.

You called broadcastMessage(), and it errored.

Note the difference. xpcall takes a function, you performed a function call whose result was passed to xpcall (or in this case, the function errored before it even got that far).
Find
Reply
14-02-2015, 04:56 PM,
#5
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: xpcall failed
(14-02-2015, 04:53 PM)Person8880 Wrote: Of course, xpcall can't catch something before it's even received its arguments.

You called broadcastMessage(), and it errored.

Note the difference. xpcall takes a function, you performed a function call whose result was passed to xpcall (or in this case, the function errored before it even got that far).

Then I didn't really understund how this function works. Thanks I will try this.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
14-02-2015, 04:58 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: xpcall failed
It's a very common mistake for people new to Lua. I did it too when I was starting out!

Just have to see functions more as variables than anything special and it starts to make more sense.
Find
Reply
14-02-2015, 05:11 PM,
#7
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: xpcall failed
(14-02-2015, 04:58 PM)Person8880 Wrote: It's a very common mistake for people new to Lua. I did it too when I was starting out!

Just have to see functions more as variables than anything special and it starts to make more sense.

T-16 and me were thinking if there could be real example for every function.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
14-02-2015, 05:15 PM,
#8
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: xpcall failed
That would take quite a long time to do!

The docs do support it (see the preprocessor directives), so we'll see.
Find
Reply
14-02-2015, 05:18 PM,
#9
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: xpcall failed
(14-02-2015, 05:15 PM)Person8880 Wrote: That would take quite a long time to do!

The docs do support it (see the preprocessor directives), so we'll see.

I know bunch of those functions as well. You could always let me help. Big Grin

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.