Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to save Time.time data into a list

Discussion in 'Scripting' started by tsuiisaac02, Mar 7, 2023.

  1. tsuiisaac02

    tsuiisaac02

    Joined:
    Nov 13, 2022
    Posts:
    1
    Thanks for taking the time to read this message.

    In unity I am aiming to record the Z euler angle of an game object every fixed time interval and output this as a CSV file, with the time in the left collumn and the corresponding euler angle in the second collumn.

    I recieve this error

    Assets\scripts\debug\ConcatArray.cs(28,21): error CS0029: Cannot implicitly convert type 'float' to 'System.Collections.Generic.List'

    This is my attempt and have tried changing the variable type of 'Time count' to 'System.Collections.Generic.List', but i still recieve the same error.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq; // allows for concat?
    5.  
    6. public class ConcatArray : MonoBehaviour
    7. {
    8.     public string fileName = "Assets/Resources/test.txt"; // file pathname
    9.     private List<float> AnglesOne;
    10.     private List<float> TimeCount;
    11.     private float[] DoublePendulumData;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         AnglesOne = new List<float>();
    17.         TimeCount = new List<float>();
    18.         DoublePendulumData = new float[] { 15, 1645, 135, 567 };
    19.  
    20.     }
    21.     void RecPoint()
    22.     {
    23.         // store position...
    24.         AnglesOne.Add(transform.eulerAngles.z);
    25.        
    26.  
    27.         //Store time... capital T?
    28.         TimeCount = Time.time;
    29.  
    30.     }
    31.     void SaveToFile(string fileName)
    32.     {
    33.         System.IO.File.WriteAllText(fileName, ""); // clear old file, if any
    34.  
    35.         DoublePendulumData = TimeCount.Concat(AnglesOne).ToArray();
    36.     }
    37.  
    38.     void OnGUI()
    39.     {
    40.         if (GUI.Button(new Rect(10, 10, 120, 30), "Save"))
    41.         {
    42.             CancelInvoke("RecPoint"); // stop recording
    43.             SaveToFile(fileName); // save positions
    44.         }
    45.     }
    46.  
    47. }
    48.  
     
  2. Joggla

    Joggla

    Joined:
    Dec 2, 2019
    Posts:
    88
    TimeCount is a List... so if you want to add the time to the list you do
    Code (CSharp):
    1. TimeCount.Add(Time.time);
     
    Bunny83 likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Please don't double post for the same typing mistakes. You can fix your own typing mistakes this way:

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    Some help to fix "Cannot implicitly convert type 'Xxxxx' into 'Yyyyy':"

    http://plbm.com/?p=263