• Minor LUA issue
    6 replies, posted
So to start off with, yes I am fairly new to Lua and I'm trying to learn it by looking at existing scripts and modifying them and then merging ideas together. It's what works for more more efficently. Anyway, for my problem, I am trying to make it so that when the admin presses the button within the menu, they are prompted with a box that says 'Write here...' and then whatever they write in their gets displayed on all current players' screens as the @@@ chat function does. However when I am using the code I have written, what happens is instead of the output being [CODE]@@@Test[/CODE] it becomes [CODE]@@@" "Test[/CODE] I've tried modifying it as much as I can to my knowledge, so instead I've come to these forums. This is the code that is responsible for the output. [CODE] function makeAnnouncement() local dp = vgui.Create("DFrame") dp:SetSize(400,75) dp:Center() dp:SetTitle("Write your announcement") dp:MakePopup() local dte = vgui.Create("DTextEntry",dp) dte:SetSize(200,30) dte:SetPos(30,25) dte:CenterHorizontal() dte:SetValue("Write here...") dte.OnEnter = function(self) reason = self:GetValue() RunConsoleCommand("say"," @@@", reason) dp:Close() end end[/CODE]
You need to concatenate the strings using '..'. eg:[code]print("This" .. " is " .. "concatenation")[/code]
[QUOTE=txike;51781323]You need to concatenate the strings using '..'. eg:[code]print("This" .. " is " .. "concatenation")[/code][/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunConsoleCommand]RunConsoleCommand[/url] takes variadic arguments. If you concatenate them, it doesn't work.
[QUOTE=James xX;51781592][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunConsoleCommand]RunConsoleCommand[/url] takes variadic arguments. If you concatenate them, it doesn't work.[/QUOTE] It does that to separate arguments, considering say only takes one argument, he needs to concatenate them. Edit: Also that space in front of @@@ can be removed.
I thought "say" was protected by FCVAR_SERVER_CAN_EXECUTE
[QUOTE=James xX;51781592][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunConsoleCommand]RunConsoleCommand[/url] takes variadic arguments. If you concatenate them, it doesn't work.[/QUOTE] Yeah I got it confused with ply:ConCommand.
[QUOTE=txike;51781323]You need to concatenate the strings using '..'. eg:[code]print("This" .. " is " .. "concatenation")[/code][/QUOTE] Fixed! :) Incase anyone is wondering here's what I did instead [CODE]RunConsoleCommand("say","@@@"..reason)[/CODE] Thanks alot
Sorry, you need to Log In to post a reply to this thread.