Code: Select all
function gadget:GetInfo()
return {
name = "CUTests",
desc = "creates units",
author = "zwzsg (and then horribly ruined by Voidranaut)",
date = "not sure",
version = "1.0",
license = "Public Domain",
layer = 0,
enabled = true
}
end
local message_identifier = gadget:GetInfo().name..": "
local once = 1
if (gadgetHandler:IsSyncedCode()) then--SYNCED
function gadget:RecvLuaMsg(msg,player)
local MsgForMe=string.match(msg,message_identifier.."(.*)")
if MsgForMe then
Spring.Echo("Synced recieved a message from unsynced:")
Spring.Echo(MsgForMe)
if( once == 1) then
Spring.CreateUnit( 367, 7110, 2700, 38,(0), 1, 0 )
once = 0
end
end
end
else--UNSYNCED
function gadget:KeyPress(key) --key scope exists within the function
if( key == 121 ) then
for _,u in ipairs(Spring.GetAllUnits()) do
Spring.SendLuaRulesMsg(message_identifier..u.." was pressed")
Spring.Echo( u )
end
end
Spring.Echo("Key "..key.." pressed in unsynced")
Spring.SendLuaRulesMsg(message_identifier..key.." was pressed")
end
end
when I hit the key to trigger the event I get this error
Code: Select all
Key 121 pressed in unsynced
[ 833] Synced recieved a message from unsynced:
[ 833] 6344 was pressed
[ 833] LuaRules::RunCallIn: error = 2, RecvLuaMsg, [string "LuaRules/Gadgets/cutests.lua"]:29: Unsafe attempt to change game state
[ 833] Synced recieved a message from unsynced:
[ 833] 2738 was pressed
[ 833] LuaRules::RunCallIn: error = 2, RecvLuaMsg, [string "LuaRules/Gadgets/cutests.lua"]:29: Unsafe attempt to change game state
[ 833] Synced recieved a message from unsynced:
[ 833] 1096 was pressed
[ 833] LuaRules::RunCallIn: error = 2, RecvLuaMsg, [string "LuaRules/Gadgets/cutests.lua"]:29: Unsafe attempt to change game state
[ 833] Synced recieved a message from unsynced:
[ 833] 121 was pressed
[ 833] LuaRules::RunCallIn: error = 2, RecvLuaMsg, [string "LuaRules/Gadgets/cutests.lua"]:29: Unsafe attempt to change game state
now there is alot of this error that is undoubtibly because I badly wrote the scirpt BUT my BIGGEST question does come from this part here
Code: Select all
Unsafe attempt to change game state
(loard know I did 100 things wrong on this scirpt but that is my main quesiton)