SaveGame v. 0.6 - Page 3

SaveGame v. 0.6

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

Re: SaveGame v. 0.1

Post by Argh »

Noooooooo.

Dammit. OK, going to sleep on this. Back to evil recursion.
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: SaveGame v. 0.1

Post by SpliFF »

If your recursive save isn't working yet have a look at this Dump() function. It's a minor variation on what I used to pretty-print and serialise tables in Supreme Commander's Multiplayer Save Mod.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

I tested, none of the basic cases failed...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Must be something wrong over here, then. I've had some sleep; I'll take a look here in a little bit. I'd like this done before it's time to have a life today- whatever's wrong, it's a very weird bug, probably some really stupid thing I'm missing that's screwing up the state of GG in general.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

I think it's fixed now. Error was stupid (wow, go figure): a loop wasn't built correctly, and when I fixed that, I also exposed (and fixed) another bug. So hopefully this resolves a few things.

Here's the current version (including the Reset Button and removal of modinfo.tdf).
Attachments
SAVEGAMES.sdd.zip
(381.97 KiB) Downloaded 22 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

Hrmm. Seems like things like CMD.GUARD (stuff that needs a valid unitID) still aren't working right.

This is really weird.

The savegame uses a delayed approach, where it looks for Units that were built on the previous gameframe. It's finding valid UnitIDs, and I'm quite sure it's passing the right command.

But... nothing happens. I don't get an error, but CMD.GUARD doesn't seem to get activated, either.

Code: Select all

DelayedCall(function()
me = Spring.GetUnitsInSphere(609.37530517578,378.8688659668,166.90707397461,16)
if me[1] ~= nil then
GiveOrderToUnit(u,CMD.GUARD,{me[1]},{"shift"})
Spring.Echo(u,me[1])
else Spring.Echo("no Unit found") end
end)
I get that Echo from Spring.Echo(u,me[1]), it's two integers, so it must be finding two UnitIDs. Yet... nothing happens. Very strange.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: SaveGame v. 0.2

Post by Tobi »

Why don't you just make a map from old unitID to new unitID,

Code: Select all

oldToNewUnitID[oldUnitID] = Spring.CreateUnit(...)
And pass all (guard) commands that contain a unitID with code similar to this:
(as a second pass after ALL units are created of course)

Code: Select all

GiveOrderToUnit(u,CMD.GUARD,{oldToNewUnitID[oldUnitID]},{"shift"})
I don't really see for what you need GetUnitsInSphere...
Satirik
Lobby Developer
Posts: 1688
Joined: 16 Mar 2007, 18:27

Re: SaveGame v. 0.2

Post by Satirik »

should at least show which slot are used, nice work (even if i still think it should be done engine side)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

should at least show which slot are used
It does, when you mouse-over them, and tells you what's in the slot- the game, the map, when it was saved, adding other things (such as the mission name, campaign, whatever) can be determined at a later date.

As for whether it's engine-side or not... really, I think it's best to do it with Lua. The additional flexibility and the fact that the formatting is standard- a very simple Gadget will read a savegame that operates any way it wants to, savegame data is not tied to the actual start-script used- means that it's amenable to operation from a Lobby. All a Lobby has to do is detect whether savegame(number).txt is present, and read whatever it wants to from the start-script, and voila. While some things would be rather hard to deal with, I think that this is best solution we're likely to arrive at, and certainly the most flexible.


@Tobi: I'll try that, but I'm still puzzled why this didn't work as designed. The spheres catch the new Units' IDs when they're created, the numbers look right... but the commands aren't getting executed. Very weird. Oh well.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

Still isn't working. Very puzzling. Here are the results in the savegame, where I have a Chicken_Shocker Guarding a Chicken_Soldier. As you can see by comparing the unitIDs, everything matches up...

Code: Select all

u = CreateUnit("chicken_shocker",774.28234863281,339.65112304688,361.49600219727,0,0)
table.insert(oldToNewUnitID,314,u)
SetUnitHealth(u,1500,0,0,1)
table.insert(validTable,u,1)
Spring.MoveCtrl.Enable(u)Spring.MoveCtrl.SetRotation(u,0,9429,0)Spring.MoveCtrl.Disable(u)
DelayedCall(function()
GiveOrderToUnit(u,25,{oldToNewUnitID[4233]},{"shift"})
end)
u = CreateUnit("chicken_soldier",909.40783691406,278.31579589844,460.44421386719,0,0)
table.insert(oldToNewUnitID,4233,u)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

Hmm. Tested further, and it's absolutely, positively the right unitID.

Is there some sort of command buffer that I've exceeded, or something?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: SaveGame v. 0.2

Post by Tobi »

Is 'u' a new local for every unit? (Doesn't seem so for the code you pasted.)

It should be if you want the DelayedCall-ed function to refer to the correct unit.
(Or solve it in different way, by passing u as argument to the DelayedCall-ed function.)

EDIT:
this should work, although it's not necessarily the most clean/elegant solution ;-)

Code: Select all

do
local u = CreateUnit("chicken_shocker",774.28234863281,339.65112304688,361.49600219727,0,0)
table.insert(oldToNewUnitID,314,u)
SetUnitHealth(u,1500,0,0,1)
table.insert(validTable,u,1)
Spring.MoveCtrl.Enable(u)Spring.MoveCtrl.SetRotation(u,0,9429,0)Spring.MoveCtrl.Disable(u)
DelayedCall(function()
GiveOrderToUnit(u,25,{oldToNewUnitID[4233]},{"shift"})
end)
end
do
local u = CreateUnit("chicken_soldier",909.40783691406,278.31579589844,460.44421386719,0,0)
table.insert(oldToNewUnitID,4233,u)
end
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

No, it was just being recycled. Easy enough to change, I'll test that.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: SaveGame v. 0.2

Post by Tobi »

Oh, also, table.insert will mangle your map.

It's a map, not an array, so don't use table.insert.

Use

Code: Select all

oldToNewUnitID[oldUnitID] = Spring.CreateUnit(...)
EDIT: tested, it *may* mangle your map, it doesn't always do this ;-)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

OK.

Hmm. Absolutely no change:

Code: Select all

do
local w
w = CreateUnit("chicken_shocker",774.28234863281,339.65112304688,361.49600219727,0,0)
oldToNewUnitID[314] = w
SetUnitHealth(w,1500,0,0,1)
table.insert(validTable,w,1)
Spring.MoveCtrl.Enable(w)Spring.MoveCtrl.SetRotation(w,0,9429,0)Spring.MoveCtrl.Disable(w)
DelayedCall(function()
GiveOrderToUnit(w,25,{tonumber(oldToNewUnitID[4233])},{"shift"})
Spring.Echo(oldToNewUnitID[4233])
end)
end
do
local x
x = CreateUnit("chicken_soldier",909.40783691406,278.31579589844,460.44421386719,0,0)
Spring.Echo("new unit = "..x)
oldToNewUnitID[4233] = x
SetUnitHealth(x,1500,0,0,1)
table.insert(validTable,x,1)
Spring.MoveCtrl.Enable(x)Spring.MoveCtrl.SetRotation(x,0,8010,0)Spring.MoveCtrl.Disable(x)
GiveOrderToUnit(x,15,{544,371.86889648438,240},0)
GiveOrderToUnit(x,15,{1544,203.11901855469,1128},0)
end
Maybe I'm using table.insert and screwing up the value when it's written.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

Nope.

WTF? I know I've used CMD.GUARD before in synced Lua... this is kinda ridiculous. If the unitID means the command returns nil... oh, wait, I can check that too...
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: SaveGame v. 0.2

Post by Tobi »

Maybe you can add some Spring.ValidUnitID(...) checks for debugging, to be sure the guard unit and the to-be-guarded unit exist when you give the command?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

AHA!!!!

If you pass the Command through AllowCommand:

Code: Select all

function gadget:AllowCommand(u, ud, team, cmd, param, opts)
	if cmd == CMD.GUARD then
		Spring.Echo(u,cmd,param[1],param[2], param[3],opts)
		return true
	end
end
Then the Guard command is applied. But no other commands are passed.

Something is happening that's really weird.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

Double AHA!

If I wait until after frame 32 to run everything, then everything works.

I'll try frame 17 now.

Frame 17 does not work.

It would appear that something prevents my CMD.GUARD commands from operating during the first 32 frames, and it's engine-side, it's not anything I'm running... I've double-checked.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.2

Post by Argh »

OK, I've gone through every use of AllowCommand, references to CMD.GUARD in all the archive modules that make up World Builder Editor (my test environment).

There's nothing that can or should interfere with CMD.GUARD. If I lower the frame that I perform the operations (any of them) on to lower than 32, then it fails.

So... during that first second, what's going on? Is Spring storing a command buffer of some kind, and can't deal with all this stuff happening? I'm still very confused why killing all the commands that aren't CMD.GUARD allowed it to operate correctly, even before frame 32...
Post Reply

Return to “Lua Scripts”