Jump to content

Table question [Solved]


unknooooown

Recommended Posts

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 :P

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 :P

Hope someone here can help me. Sorry if the question is a bit confusing :P

Edited by Guest
Link to comment
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

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

Rewrote my exapmle.

This is what I mean: -v- :lol:

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...