Could someone take a look at this, and tell me what's wrong?
3 replies, posted
Title says it all.
Here's my code:
[code]
function WhenSpawningz(ply)
if file.Exists( "epixrp/savedplayerarmor" .. ply:UniqueID() .. ".txt", "DATA") then
readfromfile = file.Read( "epixrp/savedplayerarmor" .. ply:UniqueID() .. ".txt")
lines = string.Explode(";", readfromfile)
for i, line in ipairs(lines) do
data = string.Explode(";", line)
model = data[1]
speed = data[2]
health = data[3]
end
ply:ChatPrint("Your armor with " .. data[3] .. " health has been loaded")
else return false
end
end
hook.Add( "PlayerLoadout", "PlayerSpawnMessagez", WhenSpawningz )
[/code]
I'm getting this error:
[code]
[ERROR] gamemodes/darkrp/entities/entities/npc_armor/init.lua:76: attempt to concatenate a nil value
[/code]
I'm trying to get it to only print what's on line 3 in the txt document, but it does not seem to work. Could someone help?
I'm assuming data[3] does not exist, print the table check its contents.
It's printing out like this:
[code]
Data: = {
"models/player/slow/tau_commander/slow_tau_commander.mdl --model
663 --walkspeed
663 --runspeed
7836 --health
2295 --armor
",
}
[/code]
How would i go about only printing line 3 out?
Looks like your file is just a single entry in the table.
Take a look at JSONToTable and TableToJSON, it's much more convenient for storing and retrieving data in text files.
[url]http://wiki.garrysmod.com/page/util/JSONToTable[/url]
[url]http://wiki.garrysmod.com/page/util/TableToJSON[/url]
Sorry, you need to Log In to post a reply to this thread.