SaveGame v. 0.6
Moderator: Moderators
Re: SaveGame v. 0.1
Noooooooo.
Dammit. OK, going to sleep on this. Back to evil recursion.
Dammit. OK, going to sleep on this. Back to evil recursion.
Re: SaveGame v. 0.1
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.
Re: SaveGame v. 0.1
I tested, none of the basic cases failed...
Re: SaveGame v. 0.1
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.
Re: SaveGame v. 0.1
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).
Here's the current version (including the Reset Button and removal of modinfo.tdf).
- Attachments
-
- SAVEGAMES.sdd.zip
- (381.97 KiB) Downloaded 22 times
Re: SaveGame v. 0.2
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.
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.
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)
Re: SaveGame v. 0.2
Why don't you just make a map from old unitID to new unitID,
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)
I don't really see for what you need GetUnitsInSphere...
Code: Select all
oldToNewUnitID[oldUnitID] = Spring.CreateUnit(...)
(as a second pass after ALL units are created of course)
Code: Select all
GiveOrderToUnit(u,CMD.GUARD,{oldToNewUnitID[oldUnitID]},{"shift"})
Re: SaveGame v. 0.2
should at least show which slot are used, nice work (even if i still think it should be done engine side)
Re: SaveGame v. 0.2
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.should at least show which slot are used
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.
Re: SaveGame v. 0.2
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)
Re: SaveGame v. 0.2
Hmm. Tested further, and it's absolutely, positively the right unitID.
Is there some sort of command buffer that I've exceeded, or something?
Is there some sort of command buffer that I've exceeded, or something?
Re: SaveGame v. 0.2
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
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
Re: SaveGame v. 0.2
No, it was just being recycled. Easy enough to change, I'll test that.
Re: SaveGame v. 0.2
Oh, also, table.insert will mangle your map.
It's a map, not an array, so don't use table.insert.
Use
EDIT: tested, it *may* mangle your map, it doesn't always do this 
It's a map, not an array, so don't use table.insert.
Use
Code: Select all
oldToNewUnitID[oldUnitID] = Spring.CreateUnit(...)

Re: SaveGame v. 0.2
OK.
Hmm. Absolutely no change:
Maybe I'm using table.insert and screwing up the value when it's written.
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
Re: SaveGame v. 0.2
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...
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...
Re: SaveGame v. 0.2
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?
Re: SaveGame v. 0.2
AHA!!!!
If you pass the Command through AllowCommand:
Then the Guard command is applied. But no other commands are passed.
Something is happening that's really weird.
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
Something is happening that's really weird.
Re: SaveGame v. 0.2
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.
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.
Re: SaveGame v. 0.2
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...
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...