Code: Select all
if condition == 'value' then
Moderator: Moderators
Code: Select all
if condition == 'value' then
enabled = false
Code: Select all
[ 0] Failed to load: spacerock.lua ([string "LuaRules/Gadgets/spacerock.lua"]:19: attempt to index field '?' (a nil value))
wouldnt you need something like falling_meteor and crashed_meteor then instead of just meteor?I guess the logic i'm shooting for is. A Rock is created then it falls to the ground and explodes, hurting near by units. Then just after it explodes it is replaced with a reclaimable feature. Is my code not congruent with my logic?
It will fail at 2nd call to CreateUnit and you will see a error message stating that recursion is not permitted.knorke wrote:And calling CreateUnit in the UnitCreated callin will cause UnitCreated to be once again. Then another unit will be created by CreateUnit. This will cause UnitCreated to called etc. A never ending circle!
Code: Select all
function widget:AddConsoleLine(msg, priority)
Spring.Echo ("blabla")
end
Just spam. Not freeze spring as UnitCreated would with recursion.knorke wrote:will spam your chat though.
Code: Select all
local testUnitDefID = UnitDefNames[testUnitName].id
Code: Select all
function gadget:GetInfo()
return {
name = "Space Rock",
desc = "Spawns rocks from space.",
author = "oksnoop2",
date = "4/24/2010",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true, -- loaded by default?
}
end
if not gadgetHandler:IsSyncedCode() then
return false -- no unsynced code
end
----- Settings -----------------------------------------------------------------
local meteorDefName = "f1" -- meteor unit name, use a unit with a death explosion
local meteorInterval = 1 -- time between the arrival of meteors, in seconds
local fallGravity = 1
local meteorSpawnHeight = 5000
local burnEffect1 = "smallburn" -- CEG used for the meteor trail, needs to be visible out of los
local burnEffect2 = "medburn"
----------------------------------------------------------------------------------
local meteors = {} -- meteor set
function gadget:GameFrame(frame)
if frame % (30 * meteorInterval) == 0 then
-- pick a random location as the meteor spawn point
local meteorSpawnX = math.random(Game.mapSizeX)
local meteorSpawnZ = math.random(Game.mapSizeZ)
local meteorSpawnY = Spring.GetGroundHeight(meteorSpawnX, meteorSpawnZ) + meteorSpawnHeight
-- create the meteor
local meteorID = Spring.CreateUnit(meteorDefName, meteorSpawnX, meteorSpawnY, meteorSpawnZ, "n", Spring.GetGaiaTeamID()) -- will ignore Y and spawn at ground level
meteors[meteorID] = true -- put it in the meteor set
Spring.MoveCtrl.Enable(meteorID) -- tell spring we'll take care of moving the meteor
Spring.MoveCtrl.SetPosition(meteorID, meteorSpawnX, meteorSpawnY, meteorSpawnZ) -- this time the height will be set correctly
Spring.MoveCtrl.SetGravity(meteorID, fallGravity) -- make gravity affect the meteor
end
for meteorID in pairs(meteors) do -- loop through every meteor in the meteor set
local x, y, z = Spring.GetUnitPosition(meteorID)
local h = Spring.GetGroundHeight(x, z)
if y < h then -- if the meteor below ground level
Spring.DestroyUnit(meteorID) -- make it explode
meteors[meteorID] = nil -- remove it from the meteor set
else -- above ground, show the meteor trail
Spring.SpawnCEG(burnEffect1, x, y + 30, z)
Spring.SpawnCEG(burnEffect2, x, y, z)
end
end
end