Factory commands... and Lua

Factory commands... and Lua

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Factory commands... and Lua

Post by Argh »

Basically, I've found a few things that, imo at least, seem to be major bugs, in terms of factory / Lua interaction:

1. You can use Spring.EditUnitCmdDesc(u, cmdID, {hidden = true}) to hide a build-menu option, but you may not show it later by setting it to false. I tried various contexts, and it just doesn't seem to work. It's specific to build-menu commands (i.e., negative numbers).

2. Same goes for disabled = true. You can disable it, you may not re-able it.

3. You cannot insert a new build command into a Unit, even if that Unit has that build command as part of it's UnitDef. IOW, if you remove it, it's gone forever.

It's weird. Hiding / showing etc. works just fine, for all command IDs in the positive range, but only works one way for negative ones.

I know that the build-menu stuff is being handled differently than other elements, but the one-way nature of it is very strange, and made what should have been a very simple task into something like 6 hours of forehead-bashing and frustration :P
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Factory commands... and Lua

Post by KDR_11k »

Hidden = false works fine for me, same for disabled. And yes, that IS on a factory.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Factory commands... and Lua

Post by Argh »

For build commands, or for fakes? I looked at THIS v4, and you're not using real build commands, you're just using fakes, generated through your customParams, using an odd range based off of 31000.

Moreover, you're doing it per-team, whereas I need to do it per-Factory:

Code: Select all

local function MakeSmallAvailable(team, ud)
	for b,_ in pairs(builder) do
		for _,u in ipairs(Spring.GetTeamUnitsByDefs(team,b)) do
			local f = Spring.FindUnitCmdDesc(u, CMD_BUILD + ud)
			if f then
				Spring.EditUnitCmdDesc(u, f, {disabled = false})
			end
		end
	end
end
Fakes and other positive-numbered command IDs worked just fine, in short it's just negatives that bork.

In an ideal world, I would have just used InsertUnitCmdDesc() to put the relevant Units into my Builder's list, and been done with the whole thing in half an hour (first attempt was just basically "if builder == blah, then insert commands blah blah blah", which should have worked) but if you pass that a negative commandID, Spring gives you an error, says that the param is wrong. Just plain strange.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Factory commands... and Lua

Post by KDR_11k »

It was in a test version of Gundam and that uses real build commands.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Factory commands... and Lua

Post by Kloot »

Build cmdID's (not cmdDescID's, which must be >= 0) are identified via -unitDefID, nothing more. There is no CMD_BUILD command ID unless you define one yourself.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Factory commands... and Lua

Post by Argh »

It was in a test version of Gundam and that uses real build commands.
You just sent Spring.EditUnitCmdDesc(u, -unitID, {disabled = false}), and it worked, for a build command? Because I'm telling you, it just didn't work for me. No error, it just didn't do anything. Same with hidden = false. And yes, I confirmed and re-confirmed the unitID and unitDefID a bazillion times, I know I was using all the right data.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Factory commands... and Lua

Post by jK »

Argh wrote:Spring.EditUnitCmdDesc(u, cmdID, {hidden = true})
Argh wrote:Spring.EditUnitCmdDesc(u, -unitID, {disabled = false})
wiki says:
Spring.EditUnitCmdDesc( number unitID, number cmdDescID, table cmdArray ) -> nil

CmdDescID != CmdID
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Factory commands... and Lua

Post by Argh »

Oh.

Damn, I hate it when you're right. That's probably it. Sheesh :roll:

I guess I'll just have to re-write the damn thing then, the method I used was terrifying orkish work.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Factory commands... and Lua

Post by KDR_11k »

(just use FindUnitCmdDesc...)
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Factory commands... and Lua

Post by lurker »

Kloot wrote:Build cmdID's (not cmdDescID's, which must be >= 0) are identified via -unitDefID, nothing more. There is no CMD_BUILD command ID unless you define one yourself.
I think that was the code from THIS.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Factory commands... and Lua

Post by KDR_11k »

Yeah, that's why it's using CmdDescIds correctly :P.
Post Reply

Return to “Engine”