SaveGame v. 0.6 - Page 2

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 »

Result: {testingsave={hello={kitty=cat}}}

So... is GG = {testingsave={hello={kitty=cat}}} the same as GG.testingsave = {hello = {kitty = cat}} (the original test value)? That looks right...
Last edited by Argh on 23 Jan 2010, 04:19, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

GG['testingsave'] == GG.testingsave

try it with multiple vars in one or more of the tables, make sure it handles that right

...

you don't want strings encased in quotes?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Hmm. Two first-iteration values:

{testingsave={hello={kitty=cat}},foo={bar={barfoo=boo}}}

Original:

GG.testingsave = {hello = {kitty = 'cat'}}
GG.foo = {bar = {barfoo = 'boo'}}

That second one looks like exactly what is needed: GG = { foo={bar={barfoo=boo}}, }
Oops, nvm, wasn't counting brackets lol, there's one too many.

GG = { foo={bar={barfoo=boo}}, }
not
GG = { foo={bar={barfoo=boo}}}, }
Last edited by Argh on 23 Jan 2010, 04:28, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

Code: Select all

{
	testingsave={
		hello={
			kitty=cat
		}
	},
	foo={
		bar={
			barfoo=boo
		}
	}
}
brackets are right, based on "{testingsave={hello={kitty=cat}},foo={bar={barfoo=boo}}}"
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Ohhh, it's enclosing the whole thing. OK.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

right, because GG is a table. do you want it to put quotes around strings?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Yeah. I just ran into that fun problem.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

is that a yes? if so, try this.

Code: Select all

local function dumpTable(tab)
	if type(tab) == 'table' then
		local tmp = {}
		for a, b in pairs(tab) do
			table.insert(tmp, a .. '=' .. dumpTable(b))
		end
		return '{' .. table.concat(tmp, ',') .. '}'
	elseif type(tab) == 'string' then
		return "'" .. tab .. "'"
	else
		return tab
	end
end
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Hmm. GG.testingsave == nil

So... um, I guess surround all a's with quotes if not numbers?

Or... GG['testingsave']... shit

Nope.

GG ={['testingsave']={['hello']={['kitty']='cat'}},['foo']={['bar']={['barfoo']='boo'}}}

Both GG.testingsave and GG['testingsave'] return nil

With this function (was going to add math check, but whatever

Code: Select all

local function dumpTable(tab)
   if type(tab) == 'table' then
      local tmp = {}
      for a, b in pairs(tab) do
         table.insert(tmp, "['"..tostring(a).."']".. '=' .. dumpTable(b))
      end
      return '{' .. table.concat(tmp, ',') .. '}'
   elseif type(tab) == 'string' then
      return "'" .. tab .. "'"
   else
      return tab
   end
end
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

['testingsave']=
what?
I have no idea why you added that except possibly to break it.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

IDK. Sorry, been up since 5AM, I am now officially punch-drunk.

Whatever's going on, the top-level reference doesn't return <table>
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Wait, I think I got it... did something really silly
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

did it possibly have something to do with the only line you changed?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

No, and it didn't work, either. I still get a value of nil for GG.testingsave.

This is really amazingly stupid. I did a few things like this before I ended up with the hand-coded recursions.

The problem is, GG.testingsave = {blah = {blahblah = 1}} does not appear to be equivalent to GG = {testingsave = {blah = {blahblah = 1}}}
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

Code: Select all

> GG = {}
> GG.testingsave = {blah = {blahblah = 1}}
> ZZ = {testingsave = {blah = {blahblah = 1}}}
> print(dumpTable(GG))
{testingsave={blah={blahblah=1}}}
> print(dumpTable(ZZ))
{testingsave={blah={blahblah=1}}}
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Hmm. Code in save-file:

GG ={testingsave=2,foo={bar={barfoo=boo}}}

Spring.Echo(GG.testingsave) returns nil
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

Code: Select all

local function dumpTable(tab)
	if type(tab) == 'table' then
		local tmp = {}
		for a, b in pairs(tab) do
			table.insert(tmp, tostring(a) .. '=' .. dumpTable(b))
		end
		return '{' .. table.concat(tmp, ',') .. '}'
	elseif type(tab) == 'string' then
		return "'" .. tab .. "'"
	else
		return tostring(tab)
	end
end
added tostring fallback for types that don't concat well

what's GG? does it allow direct assignment? I'm guessing not.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

GG's the gadget global table.

Meh. In previous tests (with that ugly iterative hack):

GG.testingsave = {foo = {bar = barfoo}}
Worked both ways. But that code rebuilds it exactly like that.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: SaveGame v. 0.1

Post by aegis »

Code: Select all

for a,b in pairs (GG) do
	Spring.SendLuaUIMsg('write_save_file ' .. 'GG.' .. tostring(a) ..'=' .. dumpTable(b))
end
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: SaveGame v. 0.1

Post by Argh »

Yeah... that looks like it'll do it.
Post Reply

Return to “Lua Scripts”