Can only recognize last element of Table? (Getting "Attempted to create unknown entity type" for HL2 Weapons?

(If you want to cut to the chase just scroll down to HERE’S THE PROBLEM)

Hello,

I am creating a pseudo “Nazi Zombies Mystery Box” Vending Machine that offers you choices to narrow down specific categories of weapons to randomly give you.

This addon is being set so that it creates a folder in Garrysmod/garrysmod/data: and populates the folder with a text file for each table/category of weapons you can choose from.
(It only WRITES these files if it checks and finds that they do not exist, other than this, they are never again altered by the code: I want this addon to be configurable so people can add whatever weapons they please to it)

This is all working fine up until we get to this function:

And here is the one file I have made for testing.

screen2

HERE’S THE PROBLEM
screen4

For a reason I can not figure out for the life of me, the machine is only able to create the last weapon of the table/file, even though the Classnames are correct.

I have tried everything I can think of, and I imagine I am unable to figure it out due to my inexperience here.
I am almost sure what I am doing wrong is so painfully simple and obvious to everybody else but me.

I am stumped.

Thank you in advance for anybody who takes a look at this.

Try doing string.Explode("%c", FileRead, true)

Only theory that comes to mind is that there’s an invisible character that doesn’t appear in the last item and that doesn’t display on the console.

You definitely have windows style line endings in your text file that look like “\r\n” - that results in every non-last string having extra invisible char. Your best approach there is to trim whitespace characters from every line.

2 Likes

Thank you for getting back to me,

"%c" worked but it also created lines of empty space between each selection. I suppose I could make it check for nil lines and to either skip to the next one or just not add them to the table.

However, I actually tried “/r/n” and that seemed to do it!

2 Likes

Didn’t know about \r\n, good catch.

1 Like

Yeah, that did the trick:
but again, thank you for your suggestion and getting back to me so quickly.