unknooooown Posted August 10, 2011 Share Posted August 10, 2011 (edited) Hi. Quick question. If I have a table called "table1" and something inside the table called "LoremIpsum" - Is there some way I can get that table, not by using "table1.LoremIpsum", but get the last word, in this case LoremIpsum, from another place? Like otherPlace = "LoremIpsum" and then use table1.otherPlace ? Here is a small example: Note, that this is how I am trying to do it now, and ofc, its not working as I want it to Server Side: table1 = { ["LoremIpsum"] = 1 } function getInfo(blah1) local item1 = blah1 outputChatBox("Output: "..table1.item1) -- If it works like I want it to, this should output "1" end addEvent("whenTriggeredClientSide",true) addEventHandler("whenTriggeredClientSide",getRootElement(),getInfo) Client Side: function setInfo() local client = getLocalPlayer() local blah1 = "LoremIpsum" triggerServerEvent(whenTriggeredClientSide,client,blah1) end Note, this is just a small example I made to show what I mean. Dont care about "That wouldnt work!".. The script is just to explain myself better Hope someone here can help me. Sorry if the question is a bit confusing Edited August 10, 2011 by Guest Link to comment
Castillo Posted August 10, 2011 Share Posted August 10, 2011 table1 = { ["LoremIpsum"] = 1 } function getInfo(blah1) local item1 = blah1 outputChatBox("Output: "..table1[item1]) -- If it works like I want it to, this should output "1" end addEvent("whenTriggeredClientSide",true) addEventHandler("whenTriggeredClientSide",getRootElement(),getInfo) That? Link to comment
unknooooown Posted August 10, 2011 Author Share Posted August 10, 2011 Thank you for the reply Snake. I have also tried that, but it didnt work My example was a bit stupid, because I am actually using it like this in my script:- giveWeapon(source, table1[item1], 1) -But ofc still with the same basic build as my example. Dont know if it makes a difference when I use it in the giveWeapon function? Link to comment
Castillo Posted August 10, 2011 Share Posted August 10, 2011 I actually didn't understood you so good. You are asking if you can do something like this: local myTable = {myValue1 = 1, myValue2 = 2} outputChatBox(tostring(myTable.myValue1)) outputChatBox(tostring(myTable.myValue2)) ? Link to comment
unknooooown Posted August 10, 2011 Author Share Posted August 10, 2011 Rewrote my exapmle. This is what I mean: -v- Server Side table1 = { ["DesertEagle"] = 24 } function getInfo(blah1) local item1 = blah1 giveWeapon(source,table1[item1],1) end addEvent("whenTriggeredClientSide",true) addEventHandler("whenTriggeredClientSide",getRootElement(),getInfo) function setInfo() local client = getLocalPlayer() local blah1 = "DesertEagle" triggerServerEvent(whenTriggeredClientSide,client,blah1) end Link to comment
unknooooown Posted August 10, 2011 Author Share Posted August 10, 2011 Lol.. Nvm.. I solved the problem giveWeapon(source,tostring(table1[item1]),1) Link to comment
Castillo Posted August 10, 2011 Share Posted August 10, 2011 Isn't that what I said in my first reply? P.S: Use tonumber() not tostring() Link to comment
unknooooown Posted August 10, 2011 Author Share Posted August 10, 2011 Yeah, I did use tonumber() tostring() was a mistype in here Thank you for the help. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now