Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Exmax

OpenSecurity - From table to string

Question

Hello, for a few last days now, I've been having hard times with lua. I'm using OpenSecurity addon, but this problem I'm having more with lua. When I use Entity Detector it returns me table with info about entities around it. I can print those with function 

for k, v in pairs(output[1]) do
  print(k, v)
end

but I don't know how to make from this table unique variable strings, so I could have checked if the entity is me or not. I know that it will probably be some easy function, but I can't find it anywhere on the internet. I'm almost beginner in Lua, so please don't kill me :D

Thanks :)

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

I don't really know how to work with it, when I want for each line and each thing in it separated variable. To explain it more, when i use this function it returns my with something like this

range  3.7132311
name   Player
locked false
uuid   dsadadasda-dasdaxas-dasdsxasa-dasdsaxsa
data   somedata

I want to get somehow, that variable name will return me string "Player"

Link to post
Share on other sites
  • 0

Not sure if name is for the entity's type, or the name of the player. Try this:

for i, element in ipairs(output)
  print(element.name)
  print(element.uuid) -- those 2 are for debugging purposes first, you can remove them if it works.
  if element.name == "urnamehere" do  --you should use element.uuid instead
  	yourcode()
  	break
  end
 end

If player.name is not your expected output, use element.uuid and your uuid instead, which is recommended anyway.

Edited by LightningShock
fixed code
Link to post
Share on other sites
  • 0

Tables are like lists. Sometimes you want and ordered list. Sometimes the order doesn't really matter logically but the categories or types of things in your list matter.

Ordered tables uses indexes(numbers) as accessors to values in a list(table). Property tables use keys(strings) as accessors to values. Take these examples.

-- # An ordered list. (table)
local groceries = {
  [1] = 'apples', [2] = 'oranges', [3] = 'cereal', [4] = 'frozen pizza'
}

print( groceries[1], groceries[3] ) -- # output:>> 'apples'		'cereal'


-- # A table with properties. Usually a good reason to use properties is so we can describe objects of our own. i.e.
local Player = {
  name = 'Molinko',
  health = 75,
  isAdmin = false,
  inventory = {
  	'pickaxe', 'golden apple', 'keyboard', 'some other items...'
  }
}

print( Player.name, Player.health ) -- # output:>> 'Molinko'	'75'

 

20 hours ago, Exmax said:

I want to get somehow, that variable name will return me string "Player"

If I'm understanding you then what you're looking for is this...

-- # Assuming the table 'output' is the object with information..
print( output.name ) -- # print the value to console.

local player_name = output.name
print( player_name ) -- # Same as 'print( output.name )'

 

Link to post
Share on other sites
  • 0
2 hours ago, Exmax said:

It works, thanks :)

Good to know, so, did you stick with the name or you switched to uuid?

you might as well try changing the i variable with nil to theoretically save some memory if you are into micro-optimization like me, but I am not sure if Lua is ok with that. I would like to know if that works, please :lol:.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.