Spring.CreateUnit()
Posted: 24 Jan 2010, 04:05
I have been playing with the Spring.CreateUnit() command in the following script
the locations dictated by the x,y,z position in the Spring.CreateUnit() is just an area on the map that my first unit spawns near (I got the cowardinates from just holding my cursor over a blank peice of land)
when I hit the key to trigger the event I get this error
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
question: what exactly are the needed requirements for a unit to be "safely" spawned?
(loard know I did 100 things wrong on this scirpt but that is my main quesiton)
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)