General > Developers Corner
Lua n00b questions
krooks:
That's right, the official n00b thread!
Here's what I'm dealing with, I want a message to print on the screen when someone is killed, but I don't want it to be in the chat box, I'd rather it be in the middle of the screen.
Here's a code block,
--- Code: ---function ShowKiller(victim,inflictor,killer)
victim:ULib.csayDraw("You were been killed by "..killer:Nick()..", a "..killer:GetRoleString().."!")
--victim:draw.WordBox(8, scrW() /2, ScrH() /2, killer.Nick().." killed you. He was a "..killer.GetRoleString().."!", "ScoreboardText", Color(255,100,100,255), Color(255,255,255,100))
--victim:PrintMessage(HUD_PRINTTALK, killer:Nick().." killed you! He was a "..killer:GetRoleString())
end
hook.Add("PlayerDeath","killer name and roll",ShowKiller)
--- End code ---
There are a couple things commented out,
--- Code: ---victim:PrintMessage(HUD_PRINTTALK, killer:Nick().." killed you! He was a "..killer:GetRoleString())
--- End code ---
Is the only one that works correctly without throwing an error.
On the current line of code in use, I'm getting:
--- Quote ---...function argument expected near " ."
--- End quote ---
JamminR:
Hmm. What happens if you take out the comma at that ", a" and just, for testing, make it " a"
I'm curious if maybe ULib csay is choking, somehow, even though it's concatenated as part of the 'msg' string, on the comma, expecting the optional color, duration, or fade arguments.
If not ULib, then perhaps Lua itself. (To those more experienced than I, are commas supposed to be /escaped/ out in such a string?)
krooks:
I tried both escaping it with "\," and removing it, same error.
Megiddo:
The problem is here:
--- Code: ---victim:draw.WordBox(...)
--- End code ---
Recall (or learn!) that the ":" is syntactical sugar which is translated by Lua. For example:
--- Code: ---ply:DoSomething(a, b)
--- End code ---
Is translated to:
--- Code: ---ply.DoSomething(ply, a, b)
--- End code ---
This makes working with classes nicer since you can pass around state in a fashion that isn't insanely verbose. So the error you're getting:
--- Quote ---function argument expected near " ."
--- End quote ---
Makes sense because the ':' operator must always be followed by a function and then function arguments, where you've got "victim:draw.WordBox".
Another problem here is that draw.WordBox is a client-side function which you're attempting to run server side. SendLua might be what you're looking for in this case.
JamminR:
Meg, that's all fine and dandy, but even I'm confused.
He said
--- Code: ---victim:ULib.csayDraw("You were been killed by "..killer:Nick()..", a "..killer:GetRoleString().."!")
--- End code ---
is the line he's currently getting error with..right?
Does csayDraw in ULib use the draw.WorldBox command?
Navigation
[0] Message Index
[#] Next page
Go to full version