oh it is slighty modded from something zwzsg wrote but it said public liceance I hope thats ok
Code: Select all
function gadget:GetInfo()
return {
name = "KeyCatchEx",
desc = "Show how to catch keypresses in gadgets",
author = "zwzsg",
date = "21st of January 2010",
version = "1.0",
license = "Public Domain",
layer = 0,
enabled = true
}
end
local up_arrow,down_arrow,right_arrow,left_arrow,enter,space,dee = 273,274,275,276,13,32,100 --does nothing? there for my benifit?
local message_identifier = gadget:GetInfo().name..": " --when called will tak "KeyCatchEx" onto variable
if (gadgetHandler:IsSyncedCode()) then--SYNCED
function gadget:RecvLuaMsg(msg,player) --LuaMsg must be a place were messages can be sent to be scrootanized by all the gadgets
local MsgForMe=string.match(msg,message_identifier.."(.*)")
--main purpose is to make sure the message it reads in luamsg is from "KeyCatchEx"
if MsgForMe then
Spring.Echo("Synced recieved a message from unsynced:")
Spring.Echo(MsgForMe)
end
end
[color=#FF0000]local function blockless(u)
Spring.SetUnitBlocking(u, false)
end[/color]
else--UNSYNCED
function gadget:KeyPress(key)
--key scope exists within the function
if( key == 121 ) then
for _,u in ipairs(Spring.GetAllUnits()) do
Spring.Echo( u )
[color=#FF0000]blockless(u) [/color]
end
end
Spring.Echo("Key "..key.." pressed in unsynced")
--do the .. commands work same as + commands in say java when using the System.out.print(""); command?
--key works as a variable only because of the scope (fact it was declaired in the function right?)
Spring.SendLuaRulesMsg(message_identifier..key.." was pressed")
end
end
the error displayed looks like this
Code: Select all
14680
LuaRules::RunCallIn: error = 2, KeyPress, [string "LuaRules/Gadgets/commandadditiontets.lua"]:38: attempt to call global 'blockless' (a nil value)
question 1) what I did wrong
question 2) what exactly is the error trying to say is wrong? because I think I am missinterpriting its meaning