Commands From Chat
Moderator: Moderators
Commands From Chat
I am having problems executing any commands from chat. I really need to be able to do a /spring.echo ("something") but I get no response.
Re: Commands From Chat
Chat doesn't take Lua commands.
Re: Commands From Chat
SendCommands()
ie Spring.SendCommands ("resbar 0") to hide resource bars
edit
wops misread
ie Spring.SendCommands ("resbar 0") to hide resource bars
edit
wops misread
Last edited by knorke on 12 Dec 2010, 20:52, edited 1 time in total.
Re: Commands From Chat
So is there anyway to run a command and get a reply in chat? I need a print or echo.
Re: Commands From Chat
Nah but kalda341 is trying to do the other way around. (Not chat command in Lua, but Lua in chat commands).
Which is not possible, unless you write a special gadget to retrieve and parse and execute what's written in chat.
Which is not possible, unless you write a special gadget to retrieve and parse and execute what's written in chat.
Re: Commands From Chat
Is there any developers console in spring?
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Commands From Chat
What you can do is to bind a chat command to execute a certain function. Within that function you can e.g. call Spring.Echo().
Re: Commands From Chat
kalda341: Don't try to type Lua commands in chat. It's a chat, not a command console. Run Spring windowed, and have Notepad++ in another window with your file open. When you want to test changes, reload widget or type /luarules reload. In the gadget or widget, use Spring.Echo("Hello World!")
(There do is a way for gadgets to react to chat commands, but it's a bit tricky, not something I'd advise a noob to start with.)
(There do is a way for gadgets to react to chat commands, but it's a bit tricky, not something I'd advise a noob to start with.)
Re: Commands From Chat
Here's a widget that executes Lua commands typed in the console. It's from 2007 though, it might need some fixing.
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: cmd_doline.lua
-- brief: adds a command to run raw LUA commands from the game console
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "DoLine",
desc = "Adds '/luaui <run|echo> ...' to run lua commands (for devs)",
author = "trepan",
date = "Jan 8, 2007",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Low level LUA access
--
local function RunCmd(cmd, optLine)
print(optLine)
local chunk, err = loadstring(optLine, 'run')
if (chunk == nil) then
print('doline error: ' .. err)
else
local success, err = pcall(chunk)
if (not success) then
Spring.Echo(err)
end
end
return true
end
local function EchoCmd(cmd, optLine)
local chunk, err = loadstring("return " .. optLine, 'echo')
if (chunk == nil) then
print('doline error: ' .. err)
else
local results = { pcall(chunk) }
local success = results[1]
if (not success) then
Spring.Echo(results[2])
else
table.remove(results, 1)
Spring.Echo(unpack(results))
end
end
return true
end
function widget:Initialize()
widgetHandler:AddAction("doline", RunCmd) -- backwards compatible
widgetHandler:AddAction("run", RunCmd)
widgetHandler:AddAction("echolua", EchoCmd, nil)
widgetHandler:AddAction("echo", EchoCmd, nil, "t") -- text only
-- NOTE: that last entry is text only so that we do not
-- override the default "/echo" Spring command when
-- it is bound to a keyset.
end
--------------------------------------------------------------------------------