first attempt to make a gadget

first attempt to make a gadget

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Razorblade
Posts: 47
Joined: 11 Jul 2009, 14:51

first attempt to make a gadget

Post 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
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: first attempt to make a gadget

Post by smoth »

is it in: \LuaRules\gadgets\ ?

Try adding

Spring.Echo("WAAAAAAAAAAAFFFFLES!")

should print WAAAAAAAAAAAFFFFLES in your infolog.

above your issynced check.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: first attempt to make a gadget

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: first attempt to make a gadget

Post by knorke »

number Game.mapSizeX in worldspace/opengl coords
number Game.mapSizeZ in worldspace/opengl coords
Post Reply

Return to “Lua Scripts”