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.
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?
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
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.
var myBean = new Beans();
myBean.ID = 123;
<etc>
myBeansList.Add(myBean);