- Home /
Question by
Virtual_TUe · Aug 25, 2020 at 11:50 AM ·
sliderdatacsv
How do I save slider value in a CSV file?
Hello,
I have 8 sound samples that are presented in random order to the user. The user listens to the first one. Then provides responses on 6 questions ( I will call them A,B,C,D,E,F) using 6 sliders each slider corresponding to one question. What I want is that the slider value for each of the question is saved in a csv file along with the sound number. For example:
SoundSample1, A - 78, B - 67, C - 90, D - 12, E - 89, F - 89.
The numbers against A,B,C,... indicate the slider value.
How should I do that?
Comment
Answer by andrew-lukasik · Aug 25, 2020 at 02:42 PM
// start:
string fileName = "data.csv";
string filePath = Path.Combine( Application.dataPath , fileName );
System.IO.File.WriteAllText( filePath , $"\"Sample\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"" );//creates file (overwrites old one)
var writer = System.IO.File.AppendText( filePath );// creates writer object (file lock)
// add data entries:
string sample = audioSource.clip.name;
float a = sliderA.value;
float b = sliderB.value;
float c = sliderC.value;
float d = sliderD.value;
float e = sliderE.value;
float f = sliderF.value;
writer.WriteLine( $"\"{sample}\",{a},{b},{c},{d},{e},{f}" );
// end, release file locks:
writer.Close();