maps gadget calling mods gadget functions

maps gadget calling mods gadget functions

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

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

maps gadget calling mods gadget functions

Post by knorke »

Is that possible? How?
for example I want a map to use functions for spawning resources that are defined in the mod.

maplayout.lua in map:
GameStart()
SpawnResource (800,1200)
end

resource.lua in mod:
local resource_unit = "goldnugget"
function SpawnResource (x,y)
--lots of fancy stuff to spawn the unit in correct way
--doing changes here updates all maps, ie if the name of the resource_unit is changed
end

At the moment I basically do
CreateUnit (x,y, "goldnugget")
in the maps lua and of course that is a bit fail.

Just passing over all the resources positions in some global variable thing would be ok too, so hints on this are welcome too.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: maps gadget calling mods gadget functions

Post by AF »

Could you not rearrange this and instead of doing the logic in the map, only do the mod agnostic stuff on the map, and provide the necessary data for the mod specifics? Then access the data on the mod side and do it there.

For example, the map could generate a list of positions for the spawning units, then the games gadget can read this in and do the necessary business. This should be a lot more flexible, and it means you dont need to rerelease all your maps when you change the code a little, because its only in one place, the game.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: maps gadget calling mods gadget functions

Post by knorke »

For example, the map could generate a list of positions for the spawning units, then the games gadget can read this in and do the necessary business.
Yes of course this would be fine too. Its what I meant with
Just passing over all the resources positions in some global variable thing would be ok too
The reason you said is excactly why I want this, also so that mappers dont have to tell with the confusing stuff of UnitCreate etc.

Would this be done with the _G.bla thing?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: maps gadget calling mods gadget functions

Post by knorke »

learned about including config files in #ca channel, will probally use that.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: maps gadget calling mods gadget functions

Post by Argh »

Map / Mod Gadgets are interchangeable and aren't separated in any way. Maps can call unitDefs in a specific mod, for example, without any problems at all. If you want your map to be agnostic, best (easy) result is to check the mod's name and see whether it matches, and then don't bother running, but there are more sophisticated methods, like setting a GG or G_ global, if you need to do that (be wary of order-of-operations issues, if all of this needs to happen before game start, however).
Post Reply

Return to “Lua Scripts”