• Table.Remove a String not Number
    8 replies, posted
So say i have a table thats set up like this: [CODE]"Out" { "models/props_wasteland/controlroom_chair001a.mdl" { "price" "50" "health" "100" } "models/props_interiors/vendingmachinesoda01a.mdl" { "price" "200" "health" "200" } "models/props_interiors/vendingmachinesoda01a_door.mdl" { "price" "100" "health" "200" } }[/CODE] and say i want to remove models/props_interiors/vendingmachinesoda01a_door.mdl from the table. How do i go about this because table.remove requires a number and if i put say "1" it just flips the first and last entry in the table...
Table["models/props_interiors/vendingmachinesoda01a_door.mdl"] = nil or you can set the table up like [lua] { "model" "models/props_wasteland/controlroom_chair001a.mdl", "price" "50", "health" "100", }, { "model" "models/props_interiors/vendingmachinesoda01a.mdl", "price" "200", "health" "200" }, { "model" "models/props_interiors/vendingmachinesoda01a_door.mdl", "price" "100", "health" "200" } [/lua]
[QUOTE=thegrb93;35118048]Table["models/props_interiors/vendingmachinesoda01a_door.mdl"] = nil or you can set the table up like [lua] { "model" "models/props_wasteland/controlroom_chair001a.mdl", "price" "50", "health" "100", }, { "model" "models/props_interiors/vendingmachinesoda01a.mdl", "price" "200", "health" "200" }, { "model" "models/props_interiors/vendingmachinesoda01a_door.mdl", "price" "100", "health" "200" } [/lua][/QUOTE] Or like this, if you want an index: [lua] MyTable = {} MyTable["Chair"] = { "model" "models/props_wasteland/controlroom_chair001a.mdl", "price" "50", "health" "100", }, MyTable["SodaMachine"] = { "model" "models/props_interiors/vendingmachinesoda01a.mdl", "price" "200", "health" "200" }, MyTable["SodaDoor"] = { "model" "models/props_interiors/vendingmachinesoda01a_door.mdl", "price" "100", "health" "200" } [/lua] didn't check it or anything, im at school
why you guys are writing that stuff in the form of valve keyvalues :V [lua] MyTable = { Chair = { model = "models/props_wasteland/controlroom_chair001a.mdl"; price = "50"; health = "100"; }; SodaMachine = { model = "models/props_interiors/vendingmachinesoda01a.mdl"; price = "200"; health = "200"; }; SodaDoor = { model = "models/props_interiors/vendingmachinesoda01a_door.mdl"; price = "100"; health = "200"; }; } [/lua] looks so much cleaner
[QUOTE=Hentie;35119975]why you guys are writing that stuff in the form of valve keyvalues :V [lua] MyTable = { Chair = { model = "models/props_wasteland/controlroom_chair001a.mdl"; price = "50"; health = "100"; }; SodaMachine = { model = "models/props_interiors/vendingmachinesoda01a.mdl"; price = "200"; health = "200"; }; SodaDoor = { model = "models/props_interiors/vendingmachinesoda01a_door.mdl"; price = "100"; health = "200"; }; } [/lua] Except that won't work. use commas instead of ;.. Just a hint looks so much cleaner[/QUOTE]
[QUOTE=Hentie;35119975]why you guys are writing that stuff in the form of valve keyvalues :V [lua] MyTable = { Chair = { model = "models/props_wasteland/controlroom_chair001a.mdl"; price = "50"; health = "100"; }; SodaMachine = { model = "models/props_interiors/vendingmachinesoda01a.mdl"; price = "200"; health = "200"; }; SodaDoor = { model = "models/props_interiors/vendingmachinesoda01a_door.mdl"; price = "100"; health = "200"; }; } [/lua] looks so much cleaner[/QUOTE] Wups, yeah forgot about that. Was just copying op's.
; means newline, and doesn't do anything in lua as far as i know.. it's often a habit brought over to lua from people who script C languages. but anyway you are writing all of this in key value form, why? it doesn't get made into tables automatically. it still needs to be read and then put into table form, i told you what you should do in the other thread, :) also in henties version he is storing them as variables, not string keys in the table. there really is no reason to make them variables so i'd do the key method but i don't think there is a performance difference as far as i know.
[QUOTE=LauScript;35129208]; means newline, and doesn't do anything in lua as far as i know.. it's often a habit brought over to lua from people who script C languages. but anyway you are writing all of this in key value form, why? it doesn't get made into tables automatically. it still needs to be read and then put into table form, i told you what you should do in the other thread, :) also in henties version he is storing them as variables, not string keys in the table. there really is no reason to make them variables so i'd do the key method but i don't think there is a performance difference as far as i know.[/QUOTE] I do it myself with the ; But defining a table like that using it. It will error, cause you have to use a comma as far as I know? I've just got a habit of doing it so. It's all about what you feel like. I mysql would do it like this: [lua] MyTable = {} MyTable["Chair"] = { model = "models/props_wasteland/controlroom_chair001a.mdl", price = 50, health = 100, } MyTable["SodaMachine"] = { model = "models/props_interiors/vendingmachinesoda01a.mdl", price = 200, health = 200, } MyTable["SodaDoor"] = { model = "models/props_interiors/vendingmachinesoda01a_door.mdl", price = 100, health = 200, } [/lua]
[QUOTE=Freze;35137809]I do it myself with the ; But defining a table like that using it. It will error, cause you have to use a comma as far as I know? I've just got a habit of doing it so. It's all about what you feel like. I mysql would do it like this: [lua] MyTable = {} MyTable["Chair"] = { model = "models/props_wasteland/controlroom_chair001a.mdl", price = 50, health = 100, } MyTable["SodaMachine"] = { model = "models/props_interiors/vendingmachinesoda01a.mdl", price = 200, health = 200, } MyTable["SodaDoor"] = { model = "models/props_interiors/vendingmachinesoda01a_door.mdl", price = 100, health = 200, } [/lua][/QUOTE] what..?
Sorry, you need to Log In to post a reply to this thread.