Squad Stuff

Squad Stuff

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

Moderator: Moderators

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

Squad Stuff

Post by Argh » 05 Jan 2008, 19:35

Ok, it's like this: I've gotten a "squad-builder" working for P.U.R.E. Now, instead of just building single units, the player receives a semi-randomized squad of different things.

Only one catch, though- they don't inherit the move orders of their parent properly. I keep trying various approaches, and Spring keeps telling me that I'm supplying a bad unitID, or a bad commandID. I've tried echo, to determine what's wrong, and I don't see anything wrong- so it must be something else I'm doing wrong.

Here's the code I'm using:

Code: Select all

function BuildClone(u, ud, team)
	
	local x, y, z
	x, y, z = Spring.GetUnitPosition(u)
	local MyCommandQueue
	MyCommandQueue = Spring.GetUnitCommands(u)

	MyCommandQueue = table.remove (MyCommandQueue, 1)
	Spring.Echo(MyCommandQueue)
	
	local one
	
	AllowUnsafeChanges("USE AT YOUR OWN PERIL")
	one = Spring.CreateUnit("LightMech_Spawn", x - 16,y,z, 0, team)

	Spring.Echo(one)
	
	Spring.GiveOrderToUnit(one,MyCommandQueue) 
									  
	AllowUnsafeChanges("thanks")

end
0 x

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Squad Stuff

Post by KDR_11k » 05 Jan 2008, 20:12

As you might have noticed GiveOrderToUnit takes exactly one corder. Look in the wiki, there's more functions for that.
0 x

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

Re: Squad Stuff

Post by Argh » 05 Jan 2008, 20:26

The problem I'm having is that I don't really have any clue as to which one of the many give / get things to use. They don't exactly come with good explanations as to what they do, or what to use them for. Just figuring out that Spring.GetUnitCommands was the way to get the commands currently queued was a pain.

I've just tried Spring.GiveOrderArrayToUnitMap(one,MyCommandQueue)

... infolog, with description of what these things mean, follows:

table: 063D1158 -- I dunno what this is, there are only two Echos in my script.
TABLE: table: 063D1180, table: 06441AD8, table: 06441B50, table: 0642DEC0 -- this is the table [tables] of queued commands.
4 -- this is the unitID of the clone.

Error:

LuaCob::RunCallIn: error = 2, BuildSixPack, [string "LuaCob/main.lua"]:27: GiveOrderArrayToUnitMap(): error parsing unit map

So, what in the heck is a unit map? And why is there an error?
0 x

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

Re: Squad Stuff

Post by Argh » 05 Jan 2008, 20:32

Just tried Spring.GiveOrderArrayToUnitArray(one,MyCommandQueue)

Error:

table: 08A57450
TABLE: table: 05CC39A0, table: 05CF5F58, table: 05CF6008, table: 05CF60F0, table: 05CF61B0, table: 05CF60C8, table: 05CB5790, table: 05CB5850
4
LuaCob::RunCallIn: error = 2, BuildSixPack, [string "LuaCob/main.lua"]:27: GiveOrderArrayToUnitArray(): error parsing unit array
0 x

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Squad Stuff

Post by KDR_11k » 05 Jan 2008, 21:30

You notice how it says "UnitArray"?
0 x

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

Re: Squad Stuff

Post by Argh » 05 Jan 2008, 22:46

... and? Giving me cryptic hints doesn't help much. Do I need to parse the tables of the commands out, or something?
0 x

Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Re: Squad Stuff

Post by Archangel of Death » 05 Jan 2008, 23:01

one needs to be an array of units, even if its an array of one units. So something like...

Code: Select all

local one = {}
....
one[0] = Spring.CreateUnit("LightMech_Spawn", x - 16,y,z, 0, team)
...
Spring.GiveOrderArrayToUnitArray(one,MyCommandQueue)
might work. But if it doesn't? Well... I just started to understand some of this lua stuff last week!

Pulling the tables out of the commandarray and feeding them into the new unit one by one would be another approach. But, unless an order array isn't what I think it is (a series of orders), this should work to.
0 x

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Squad Stuff

Post by KDR_11k » 05 Jan 2008, 23:06

Cryptic? That's not cryptic if you bother reading the signature provided in the Wiki.
Spring.GiveOrderArrayToUnitArray
( unitArray = { [1] = number unitID, etc... },
orderArray = {
{ number cmdID,
params = {number, etc...},
options = {"alt", "ctrl", "shift", "right"}
}, ..
}
) -> nil
Obviously the bolded section does not refer to just a number.
0 x

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

Re: Squad Stuff

Post by Argh » 06 Jan 2008, 08:55

That wasn't even slightly obvious, no.

<tests>

Nothing I've just tried has worked- it's always reporting a bad command ID. I've re-written it in at least a dozen different ways, with no change.

WTF? The command ID should be returned by Spring.GetCommandQueue, according to the documentation. Why isn't Spring reading it, and how do I fix that?

Code:

Code: Select all

function BuildSixPack(u, ud, team)

	local GetCommandQueue = Spring.GetCommandQueue	
	local x, y, z = Spring.GetUnitPosition(u)
	local MyCommandQueue = GetCommandQueue(u)

	Spring.Echo(MyCommandQueue)
	
	AllowUnsafeChanges("USE AT YOUR OWN PERIL")
	local one = Spring.CreateUnit("LightMech_Spawn", x - 16,y,z, 0, team)
	local two = Spring.CreateUnit("LightMech_Spawn", x + 16,y,z, 0, team)
	local three = Spring.CreateUnit("LightMech_Spawn", x - 16,y,z + 16, 0, team)	
	local four = Spring.CreateUnit("LightMech_Spawn", x + 16,y,z + 16, 0, team)
	local five = Spring.CreateUnit("LightMech_Spawn", x,y,z + 16, 0, team)

	Spring.Echo(one)
	
	Spring.GiveOrderArrayToUnitArray ({one,two,three,four,five}, {{MyCommandQueue},}) 										  
	AllowUnsafeChanges("thanks")

end
[EDIT] and WTF is the difference between Spring.GetUnitCommands and Spring.GetCommandQueue, anyhow? They both look identical in their output. Is Spring.GetUnitCommands just the queue for the Unit?
0 x

User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Squad Stuff

Post by jK » 06 Jan 2008, 09:21

Argh wrote:That wasn't even slightly obvious, no.
It's even in the name Spring.GiveOrderArrayToUnitArray.

And wtf is {{MyCommandQueue},} ?
[EDIT] and WTF is the difference between Spring.GetUnitCommands and Spring.GetCommandQueue, anyhow? They both look identical in their output. Is Spring.GetUnitCommands just the queue for the Unit?
they are identical
Last edited by jK on 06 Jan 2008, 09:31, edited 2 times in total.
0 x

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

Re: Squad Stuff

Post by Argh » 06 Jan 2008, 09:24

... you're still not helping. What is wrong with my syntax?
0 x

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

Re: Squad Stuff

Post by Argh » 06 Jan 2008, 09:34

And wtf is {{MyCommandQueue},} ?
That is my attempt to use what is produced by the return from Spring.GetCommandQueue(u), after KDR's comment, where he's implying that I'm not getting the value of the array. Shouldn't that return the entire value of all of the commands queued, one table at a time? I mean, I'm just trying to move tables from one unit to another, right? So, how do I do that?

Why does it keep telling me that the command ID is "bad"? And how do I get Echo to return the full contents of a Table, so that I can debug this stuff? I'd probably have already solved this mystery, if I wasn't getting hex returns from Echo, telling me absolutely nothing about the contents of the tables I'm trying to manipulate...
0 x

User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Squad Stuff

Post by jK » 06 Jan 2008, 09:38

o_O

you should check the return value of Spring.GetCommandQueue() and compare it with the input orderArray of Spring.GiveOrderArrayToUnitArray. they are different ... you need to use a different algo or you need to loop over it to convert it
0 x

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

Re: Squad Stuff

Post by Argh » 06 Jan 2008, 09:43

Can you explain that a bit more, or show me an example?

This is what I'm supposed to be getting as input:
Spring.GetCommandQueue

( number unitID [, number count] ) -> nil | commandQueueTable = {
[1] = {
"id" = number,
"params" = { [1] = number, ...},
"options" = {
"coded" = number,
"alt" = boolean,
"ctrl" = boolean,
"shift" = boolean,
"right" = boolean,
"internal" = boolean
}
}, ...
}
This is output:
Spring.GiveOrderArrayToUnitArray

( unitArray = { [1] = number unitID, etc... },
orderArray = {
{ number cmdID,
params = {number, etc...},
options = {"alt", "ctrl", "shift", "right"}
}, ..
}
) -> nil

I already have the unitID of the Unit creating the others via COB (u), and the value of the unitID I want to copy its current orders to (one).

So, how do I move that from (u) to (one)? It looks like Spring.GetCommandQueue returns a table, or series of tables. Ok, so now I should just be able to supply that table or series of tables, via Spring.GiveOrderArrayToUnitArray, as an array of tables where the first value of each table is the unitID of (one)... so, there's the problem...
0 x

User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Re: Squad Stuff

Post by Maelstrom » 06 Jan 2008, 10:54

Code: Select all

				-- Get the orders for the squad spawner
			local squad_spawner = newSquads[1].unitID;
			local squad_members = newSquads[1].members;
			
			local queue = GetCommandQueue(squad_spawner);
			
				-- If its a valid queue
			if (queue ~= nil) then  
				
				local first = next(queue, nil)
				
					-- Fix some things up
				for k,v in ipairs(queue) do
					
					local opts = v.options
					if (not opts.internal) then
						
						local newopts = {}
						if (opts.alt)   then table.insert(newopts, "alt")   end
						if (opts.ctrl)  then table.insert(newopts, "ctrl")  end
						if (opts.shift) then table.insert(newopts, "shift") end
						if (opts.right) then table.insert(newopts, "right") end
						
						if (k == first) then
							if (opts.ctrl) then
								table.insert(newopts, "shift")
							end
						end
						
							-- Give order to the units
						GiveOrderToUnits(squad_members, v.id, v.params, newopts)
						
					end
					
				end
				
			end
Snippet from a gadget I'm working on. Does basically what your wanting it to do, although it will need a bit of modification to suit your exact situation. One problem you might encounter, that I also had to work through, was that when a unit is finished building from a factory, it does not initially have any orders. I had to place the units that had finished into an array, then every GameFrame process the units in the array. Dont know if this is applicable for you, but just in case.

I think I grabbed "Fix some things up" bit from a CA Gadget, but it was a while ago so I might be wrong.
0 x

tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Re: Squad Stuff

Post by tombom » 06 Jan 2008, 11:55

OK Argh, I'm sick of your BS posts. You clearly have no idea how programming works yet insist on muddling along with it pretending you do know and wondering why nothing works. Go and read a decent programming tutorial and a Lua one. I'm sure you don't mean to sound like an idiot but you just don't understand any of it. If you spent half the time you did writing up your silly long posts you wouldn't even need to write them in the first place so don't give me a time excuse.
0 x

User avatar
AF
AI Developer
Posts: 20669
Joined: 14 Sep 2004, 11:32

Re: Squad Stuff

Post by AF » 06 Jan 2008, 11:58

Sometimes tombom posts belong in private messages. That was a prime example.

You could have at least linked him (and in turn everybody else with an itnerest) to good lua tutorials and examples. I would do so myself if I didnt have to go somewhere soon, though I may return and look anyway alter on.
0 x

tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Re: Squad Stuff

Post by tombom » 06 Jan 2008, 12:01

AF wrote:Sometimes tombom posts belong in private messages. That was a prime example.

You could have at least linked him (and in turn everybody else with an itnerest) to good lua tutorials and examples. I would do so myself if I didnt have to go somewhere soon, though I may return and look anyway alter on.
Pff, fine. I agree that it would be better in pruvate miseaages.

http://www.lua.org/pil/ - This is the obvious one although it might be a bit confusing in places if you're not completely aware of programming terminology.

ok i just woke up sorry for being so angrey in the last post. i do believe you need to look at a proper lua/programming tutorial because you're really confused about certain things and it would be really helpful for you
0 x

imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Squad Stuff

Post by imbaczek » 06 Jan 2008, 14:58

Well, Argh doesn't hide that he's not a programming guru, but a newbie; treating him bad for asking questions isn't proper.

I'd help if I knew a _good_ Lua introducion (if it was Python, I'd suggest the Python tutorial and Dive into Python, are there similar references for Lua?)
0 x

DZHIBRISH
Posts: 357
Joined: 16 Mar 2007, 22:28

Re: Squad Stuff

Post by DZHIBRISH » 06 Jan 2008, 15:10

Well,Tombom has a way with people...
He is very likable and tolerant.
0 x

Post Reply

Return to “Lua Scripts”

cron