Can you describe what's broken with the saving? On my machine turntableG_defaults is written and loaded just fine.
cheers,
Thomas
Grimm's take on the turntable anim script
Yes, sorry, that code I gave you is still using the old method. I can set up the code for the new method for you.
Jason
Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
Here you go:
And here is the error I'm getting:
Thanks Thomas,
Jason
And here is the error I'm getting:
Code: Select all
...graphics/scripts/turntableG_files/turntableG_helpers.lua:93: attempt to call field 'insert' (a nil value)
Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
Hi Jason,
The
Did the code have this parameter name originally? If yes I'm baffled how it could ever work.
cheers,
Thomas
The
table
parameter of saveTable
clashes with table.insert
. The code is shadowing the table module. The code is equivalent to this:Code: Select all
table = {} -- bad idea
table.insert(table, 4) -- above table doesn't have an insert function, we shadowed the table module
cheers,
Thomas
Hi Thomas,
Thanks for looking into it. I haven't changed anything with that code, I don't understand it enough to mess with it.
If you comment out the binds in turntableG_gui.lua and comment out the createPropertytable line in turntableG.lua while also uncommenting the regular table init line below it, you can see that it works fine with a normal table.
I got the code from the lua users wiki site:
http://lua-users.org/wiki/SaveTableToFile
Jason
Thanks for looking into it. I haven't changed anything with that code, I don't understand it enough to mess with it.

I got the code from the lua users wiki site:
http://lua-users.org/wiki/SaveTableToFile
Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
Weird, your function signature is
Anyway, I'll have a look what changes when using regular tables.
BTW, your packing your .swp files. If your using vim for coding you should use
cheers,
Thomas
function saveTable(table, filename)
and theirs is function table.save( tbl,filename )
. They hook up their code directly in the table module. Maybe you fetched it from somewhere else.Anyway, I'll have a look what changes when using regular tables.
BTW, your packing your .swp files. If your using vim for coding you should use
set nobackup
and set noswapfile
in your .vimrc. Then vim won't generate them at all.cheers,
Thomas
Oh, I see now. Sorry Thomas, yes I did change the function names and the table var. Which I probable shouldn't have done, as I don't understand the code.
I did change the functions back to how they were originally, but it didn't help. The header notes do state that the code doesn't support "Does not save Userdata, Metatables, Functions and indices of these", that is probably causing the issue. I should look for a more complete table load and save functions. Thanks,
Jason

Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
grimm wrote:Oh, I see now. Sorry Thomas, yes I did change the function names and the table var. Which I probable shouldn't have done, as I don't understand the code.I did change the functions back to how they were originally, but it didn't help. The header notes do state that the code doesn't support "Does not save Userdata, Metatables, Functions and indices of these", that is probably causing the issue. I should look for a more complete table load and save functions. Thanks,
Jason
No worries, it happens to all of us. It's part of the job

I poked around a bit and merged my bind example with your save code and it works fine in my case:
Code: Select all
--
-- Bind example script
--
-- Create the table that has the coupled value. It won't work with a regular
-- table. We need to do a bit of magic in the API.
local props = octane.gui.createPropertyTable()
--// exportstring( string )
--// returns a "Lua" portable version of the string
function exportstring( s )
return string.format("%q", s)
end
--Save a table
function saveTable(tbl, filename)
local charS,charE = " ","\n"
local file,err = io.open( filename, "wb" )
if err then return err end
-- initiate variables for save procedure
local tables,lookup = { tbl},{ [tbl] = 1 }
file:write( "return {"..charE )
for idx,t in ipairs( tables ) do
file:write( "-- Table: {"..idx.."}"..charE )
file:write( "{"..charE )
local thandled = {}
for i,v in ipairs( t ) do
thandled[i] = true
local stype = type( v )
-- only handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables, v )
lookup[v] = #tables
end
file:write( charS.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( charS..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( charS..tostring( v )..","..charE )
end
end
for i,v in pairs( t ) do
-- escape handled values
if (not thandled[i]) then
local str = ""
local stype = type( i )
-- handle index
if stype == "table" then
if not lookup[i] then
table.insert( tables,i )
lookup[i] = #tables
end
str = charS.."[{"..lookup[i].."}]="
elseif stype == "string" then
str = charS.."["..exportstring( i ).."]="
elseif stype == "number" then
str = charS.."["..tostring( i ).."]="
end
if str ~= "" then
stype = type( v )
-- handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables,v )
lookup[v] = #tables
end
file:write( str.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( str..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( str..tostring( v )..","..charE )
end
end
end
end
file:write( "},"..charE )
end
file:write( "}" )
file:close()
end
local redSlider = octane.gui.create
{
type = octane.gui.componentType.SLIDER,
width = 200,
height = 24,
minValue = 0,
maxValue = 255,
}
-- bind the value and enable properties of the slider
redSlider:bind("value" , props, "red", function (key, data) print(key, data) end)
redSlider:bind("enable", props, "enableWidth")
props.red = 255
local swatch = octane.gui.create
{
type = octane.gui.componentType.COLOUR_SWATCH,
width = 100,
height = 100,
}
-- bind the colour and enable properties of the swatch
swatch:bind("colour", props, "myColour", function (key, data) props.red = data[1] end)
swatch:bind("enable", props, "allowColourPick")
local button = octane.gui.create
{
type = octane.gui.componentType.BUTTON,
width = 100,
height = 24,
text = "Enable/Disable",
callback =
-- callback that toggles the enabled state of the ui components
function()
props.enableWidth = not props.enableWidth
props.allowColourPick = not props.allowColourPick
end
}
local layoutGrp = octane.gui.create
{
type = octane.gui.componentType.GROUP,
children = { redSlider, swatch, button },
rows = 3,
cols = 1,
padding = { 20 },
border = false,
}
saveTable(props, "/tmp/test.txt")
for k,v in ipairs(props) do print(k, v) end
local window = octane.gui.create
{
type = octane.gui.componentType.WINDOW,
width = layoutGrp:getProperties().width,
height = layoutGrp:getProperties().height,
children = { layoutGrp },
text = "Bind Example",
}
window:showWindow()
Code: Select all
return {
-- Table: {1}
{
["__octane.shadow"]={2},
},
-- Table: {2}
{
["red"]=255,
["myColour"]={3},
},
-- Table: {3}
{
255,
0,
0,
255,
},
}
__octane.shadow
. You could feed this one to your code. This table doesn't have any special meta methods. You just need to make sure you fetch it via rawget to prevent triggering some meta methods:Code: Select all
for k,v in ipairs(rawget(props, "__octane.shadow")) do print(k, v) end
cheers,
Thomas
Excellent! Thanks Thomas!
I have the save table code working now. Now the problem child is the load table function. I think the problem is that the function creates a new table and then that replaces the special properties table. I'm not sure how to handle that as I think the binds are lost in the process. I'm thinking that I will have to read in the new table and then move the data, one component at a time, over to the binded properties table?
Jason

Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
The bindings should have already happened when you create your user interface components. Indeed, you should only assign each component it's new value from the loaded table. Blindly overwriting the property table wont work.
cheers,
Thomas
cheers,
Thomas