Page 1 of 1

first attempt to make a gadget

Posted: 01 Jan 2012, 20:07
by Razorblade
hi,
I have been sticking my nose a bit into LUA and made a first attempt for a very small test gadget not for use in any game but just to get some result :D

i tryed the gadget but here is the problem:
i don't get any message ingame as i am trying to get but also i don't get any error messages

Can somebody tell me why it does not do anything or what i did do wrong ?

Code: Select all

function gadget:GetInfo()
  return {
    name      = "Test",
    desc      = "Test",
    author    = "[MW]Razorblade",
    date      = "2011",
    license   = "Test",
    layer     = 1,
    enabled   = true
  }
end






if gadgetHandler:IsSyncedCode() then

local MapSizeX, MapSizeZ = Spring.GetMapSize()
local X = Game.MapSizeX
local Z = Game.MapSizeZ


function gadget:initialize()




function gadget:GameFrame(f)
	
	local X = Game.MapSizeX
	local Z = Game.MapSizeZ
    if Game.MapSizeX > Z then Spring.Echo("hello"..MapSizeX,MapSizeZ) 
	elseif Game.MapSizeX < Z then Spring.Echo("BOO"..MapSizeZ,MapSizeX)
	 
	
	        end
    	end
	end
 end

Re: first attempt to make a gadget

Posted: 01 Jan 2012, 20:39
by smoth
is it in: \LuaRules\gadgets\ ?

Try adding

Spring.Echo("WAAAAAAAAAAAFFFFLES!")

should print WAAAAAAAAAAAFFFFLES in your infolog.

above your issynced check.

Re: first attempt to make a gadget

Posted: 01 Jan 2012, 20:39
by zwzsg
One of your end is misplaced. Also there's a capital I at Initialize (Lua is case sensitive).

Are you sure Spring.GetMapSize exists?

Don't forget to read infolog, it'll point you to most of your Lua errors.


Code: Select all




function gadget:GetInfo()
  return {
    name      = "Test",
    desc      = "Test",
    author    = "[MW]Razorblade",
    date      = "2011",
    license   = "Test",
    layer     = 1,
    enabled   = true
  }
end



if gadgetHandler:IsSyncedCode() then

    local MapSizeX, MapSizeZ = Game.MapSizeX, Game.MapSizeZ

    function gadget:Initialize()
        Spring.Echo("Hello world!")
    end

    function gadget:GameFrame(f)
        if MapSizeX > MapSizeZ then
            Spring.Echo(MapSizeX,">",MapSizeZ)
        elseif MapSizeX < MapSizeZ  then
            Spring.Echo(MapSizeX,"<",MapSizeZ)
        else
            Spring.Echo(MapSizeX,"=",MapSizeZ)
        end
    end

end

Re: first attempt to make a gadget

Posted: 02 Jan 2012, 14:10
by knorke
number Game.mapSizeX in worldspace/opengl coords
number Game.mapSizeZ in worldspace/opengl coords