Saving a row of variables into a text-file
-
hi,
with this code i can save a row of my variables to a text - file, but in one linefile = File.open("C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/zf/partemp.txt", "w") { |f|
f << lines[0].to_f
f << lines[1].to_f
f << lines[2].to_f
}when i try to separate the values by \n, there is a syntax error:
file = File.open("C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/zf/partemp.txt", "w") { |f|
f << lines[0].to_f\n
f << lines[1].to_f\n
f << lines[2].to_f\n
}no tips about this on the net.
any tips for the syntax?
thanx stan
-
You don't clarify what
lines[0]
is??f.puts(lines[0].to_f.to_s)
this adds a line of text, and
puts
automatically adds the"\n"
at the end
Why make it into a float unless you are trying to format it in some way ?
The file itself will hold only a string?Another way... if the lines in the array are already in strings is:
string=lines.join("\n")
then 'sting' is something like:
"1.2\n3.4\n5.6"
so then just do one puts into the file with:
f.puts(string)
?You need to do some more reading up on reading/writing files... and numbers versus strings etc...
-
hi tig,
ok, you are right, puts does it automatically.the declaration of the variables happens in the beginning of the ruby,
first loaded from the default file and then possibly changed by the user...these settings then create the geometry and are saved to a separate file (later as function : reload last user parameters).
will just try the puts-version.
stan
EDIT: IT WORKS
parameters are saved at the end of ruby
and
automatically reloaded on startwonderful!
Advertisement