Jump to content

Getting List of Tags


Recommended Posts

I am messing around with some testing trying to learn a few things to make a simple mod.  One of these things that I will need to do is check tags of prefabs around myself.  I have learned a little about FindEntities and how it has filters.  So for simplicity sake I just made a function that I can call from the console to print out all the tags of entities around me.

 

-- For debugging tables.
function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

G = GLOBAL
T = G.TUNING
RECIPETABS = G.RECIPETABS
Recipe = G.Recipe
Ingredient = G.Ingredient

function G.ShowMeStuff()
	
	local me = G.AllPlayers[1]
	local x,y,z = me.Transform:GetWorldPosition()
	local ents = TheSim:FindEntities(x,y,z,3)

	for k,v in pairs(ents) do			
			print(dump(v.tags))
	end	
end

 

Link to comment
Share on other sites

@Ultroman Yes I do need help. Everything that is printed comes back as nil. I have tried this around saplings, spiders, pigs, bunnymen, trees, multiplayer portal etc... Everything always returns nil.

Edited by Silisiban
Link to comment
Share on other sites

First, you should use ipairs instead of pairs when iterating a list. With pairs, k becomes the key and v becomes the value, which is valuable when you have a dictionary, but since tags WOULD BE (see below) a list, it doesn't have keys, it only has values. ipairs puts the index in k and the value in v.

More importantly, though...where did you get the idea that there's a tags variable with a list of tags? We can only use HasTag, AddTag and RemoveTag. I'm sorry I didn't think of this earlier...I was too focused on fixing the problem, that I didn't consider to think about what you were actually trying to do.

Edited by Ultroman
Link to comment
Share on other sites

@Ultroman I have no idea where I got the idea other then just logic. If there is has tag or add tag or remove tag I would assume that somewhere tags are stored to be checked.  So is there no way to find out what tags a prefab has at any given time?

Link to comment
Share on other sites

I actually don't know. I haven't been able to find anything in the code, other than this in entityscript.lua

function EntityScript:AddTag(tag)
    self.entity:AddTag(tag)
end

function EntityScript:RemoveTag(tag)
    self.entity:RemoveTag(tag)
end

function EntityScript:HasTag(tag)
    return self.entity:HasTag(tag)
end

These are functions we call. Apparently they just relay the call to the actual entity, which I believe is an engine object, which we can only access through its global functions. I can't find a script for it, at least. Perhaps v.entity.tags works?

Link to comment
Share on other sites

6 minutes ago, Ultroman said:

I actually don't know. I haven't been able to find anything in the code, other than this in entityscript.lua


function EntityScript:AddTag(tag)
    self.entity:AddTag(tag)
end

function EntityScript:RemoveTag(tag)
    self.entity:RemoveTag(tag)
end

function EntityScript:HasTag(tag)
    return self.entity:HasTag(tag)
end

These are functions we call. Apparently they just relay the call to the actual entity, which I believe is an engine object, which we can only access through its global functions. I can't find a script for it, at least. Perhaps v.entity.tags works?

Ah, there's no table that stores these tags- they're integrated as userdata since the tags are networked as strings.

To get a lump sum of tags you'd have to get the entity's debug string and parse the blob to get a list of tags.

If I recall, then the tags themselves might be limited and get truncated with some dots if it's too large.  Been a while since I used it.

Link to comment
Share on other sites

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
 Share

×
  • Create New...