How do I add more lines to this list for CSV-Exportation

I was following this tutorial on exporting data from a list to a CSV-Excel-File.

Everything works as intended by the tutorial. However in the video the creator adds information to the list through the inspector. I instead need to add the information on runtime, but I am not very experienced in the use of lists, so the answer to my question might be quite easy.

I simply need the certain lines of code that allow me to add slots to the list length and to add in the needed parameters to the added slots.

thanks in advance for any helpful advice.

Fix that. First place to start would be with the docs for List(). The .Add() method is pretty hard to get wrong. :slight_smile:

If that’s not the collection in use, then go figure out what the collection in use is and look up how to add to it.

1 Like

Yeah I know, I need to fix that, but I have issues grasping the workings of lists and other functions that do not return an immediate visible effect. But thats a topic for another day.

For now could you maybe give me a code example for that?

9639923--1370573--upload_2024-2-12_22-41-22.png

in the tutorial they create the player class and and the attributes name, health, damage defense.

What lines of code would one use in order to add one player to the list, give them a name and set all attributes to 50?

well they use arrays, and arrays are arguably designed to be fixed… So looking at this its designed to be entered in the inspector, so you could do that. Or convert to a list like Kurt mentioned, which frankly is designed to have additions and removals

1 Like

Hm, sounds like you’ve been WATCHING the tutorial and not DOING the tutorial.

Two steps to doing tutorials correctly:

  • do everything perfectly as outlined by the tutorial-maker
  • understand all parts of it enough to explain it to your dog (see my picture)

This second step can take weeks, days, months, years, but is essential to the process.

As bugfinders noted above, convert the array to a List, add the stuff you need, then convert it back.

All parts of all games done anywhere are done one tiny step at a time, building upon all previous steps, like this fellow:

Imphenzia: How Did I Learn To Make Games:

So by now I have changed my Equivalent of the “public class PlayerList” into a List.
Instead of Players and RPG roles I have Beans with different attributes.

I am now able to press “P” and add new Beans to the List in runtime and those are also present in the CSV I write by pressing “space”

however, I do not know how to adress the 16 attributes. As you can see, I tried two ways in the AddInfo() Method that didn’t work.

Once I got this to work I should be done with this issue and can move back to the stuff I know how to do.

I am aware that this is something I should know how to use on a deeper level but I learn best through repetitive usage and adjusting of tools I am given. This is how I accumulated most of my coding knowledge and it worked out well so far.

So please if you could just give me the answer, I will keep reusing and adjusting it for different situations until I have a grasp of it’s workings.

This is a very fundamental C# question you’re asking here disguised as some specific project problem. You’re asking how to create a class instance (which you’re doing when you add it to the list) and how to set its fields/properties. The reason I am stating this is that you should really follow some basic C# tutorials on this first. :slight_smile:

var myBean = new Beans();
myBean.ID = 123;
<etc>
myBeansList.Add(myBean);

https://www.w3schools.com/cs/cs_classes.php
https://www.tutorialsteacher.com/csharp/csharp-class

NOTE: When posting code, please post using code-tags and NOT using images so devs can refer to your code easier.

Thanks.

4 Likes