Reading a text file in JavaScript and then using it to create a character.

Me and my friend are making a RPG game in unity and we’ve already planned the ideas and everything for it. We understand it can take a very long time to make it, but it can be an on-going project as we have both started university and we have plenty of time (as neither of us have a job) to work on it together.

So far I have created a simple looking main menu which involves lerping and slerping the camera around. When the player clicks “play game” in the main menu, it shows 4 circles on the ground, which I have already put in place and the camera moves and focuses upon them when the player clicks on them.

What I want to do now is make it possible for the player to create a new character or edit a previous one. The plan is to have one text file for each slot which has about 50 or so lines each.

  • line 1 shows what “class” the character is (mage, warrior etc.)
  • line 2 shows the character’s level
  • line 3 to line 10 or something around there shows what level each of the characters abilities are (for example a “5” on line 6 shows that the character has 5 levels in their 3rd ability)
  • line 10 to line 20 shows what items the player has (where each item can have its own index, like a number 20 says a healing potion, for example) other lines can be added for other things like players location (which map they’re on and what x, y, z coordinates they have) and things yet to be thought of.

First i want to find out how to do the first line. I’ve already made 4 text files and put a few lines with different numbers in them for “testing”, but only the first one is important right now.

I need to make a script where the text file is read first and put into an Array(not a list, because i had no luck in finding any helpful resources of lists in Javascript. I have come to assume, you need C# to use them). After i make this array, where each element is a line in the text file, the script needs to use this to determine what prefab to spawn at the circle on the ground. I haven’t got the actual prefabs yet so i will just put spheres, capsules and cubes as stubs. My issue isn’t the use of the array. I know how to use arrays to do this, my problem is making the array in the first place.

I would absolutely be grateful if you could help me with making such an array in Javascript. I know that the ReadFile will be needed for the first line of the text file.
IF there is no javascript way of making an array, i guess i will have to learn C#, so if you give a C# answer i would still be grateful. Even if it needs to use lists i would be glad as long as you can explain how it works and how i need to make the list with the text file and THEN how i can access a specific index in the list.

Thanks,
KoshX87 =)

I am not sure if this is going to be any help as you already might know, but of course you’re going to have to use a LOT of variables. As in:

var mage : float
var warrior : float

function Update()
if (Input.GetMouseButtonDown(0))

etc… I really don’t know all of it, but that’s as simple as I’d be able to make it.
I’m new to this, if you need any help with other things though feel free to PM me. Can you do that on here? Well… You get the gist. I tried :smiley: