MakeSureToKnock Posted January 15 Share Posted January 15 You all are gonna love this one, perfectly shows how little I know of lua. Below you will find the code of what I'm trying to do. In words, I want to keep a table that keeps track of things I've inspected with a true/false that updates when I inspect something. The table will be laidout in a fashion similar to the speech_wilson file for convenence. I've hooked the inspect action to get me the inspect target. Printing the target variable gives me what I think the target id is as well as it's prefab name. I am attempting to get that prefab name alone as use it to reference the table I've built. local INSPECTIONS = { EVERGREEN = false; } --Attempting to hook inspect function local ActionLookAt_old = ACTIONS.LOOKAT.fn ACTIONS.LOOKAT.fn = function(act, ...) local targ = act.target or act.invobject print("PRE hook!") --This is it, this is what I need --prints what I am assuming is the id of the object - object name --Something like: 151502 - evergreen, but it's all one thing print(targ) --Dumb as **** but idk what Im doing local s = tostring(targ) local thing = {} for w in s:gmatch("%S+") do table.insert(thing, string.upper(w)) end --Just returns the last part of targ -- I.E. EVERGREEN but as a string print(thing[3]) a = thing[3] --I want to be able to use this, "EVERGREEN" to be able to reference and set the variable in the INSPECTIONS table --In this case it would be like INSPECTIONS.EVERGREEN = true --Something similar happens in the stringutli file but I can't seem to figure it out local INSPECTIONS[a] = true local ret = ActionLookAt_old(act) print("POST hook!") return ret end Thanks to CarlZalph for the hooking tutorial. Anyway, as you can see, I've managed to isolate the word but as a string, which IMO is dumb and the method I did it is dumb. Obviously this doesn't work and the error I get is unexpected symbol at local INSPECTIONS[a]. I'm not sure why; I think you can call tables in this way as I've seen it before, but then again... If by this point your eyes are not bleeding I've love it if someone could either point me to a reference/guild I could look deeper into or point out the thing(s) I'm doing wrong. Cheers! Link to comment Share on other sites More sharing options...
ClumsyPenny Posted January 15 Share Posted January 15 Values inside a tables aren't local variables, they're just values inside a table. So don't use local, just do: INSPECTIONS[a] = true Also, be careful because your "a" variable isn't declared to be local, so it's global. Try to avoid doing that in most cases. To get the prefab name from an entity, all you have to do is just add .prefab, like this: targ.prefab 1 1 1 Link to comment Share on other sites More sharing options...
MakeSureToKnock Posted January 15 Author Share Posted January 15 (edited) Funnily enough I was working on this again when you posted and I actually got that scuffed code to do what I wanted. However this: targ.prefab WAY better, monumentally better. Knocks that mess clean down to two lines, beautiful. I'm not lying when I say I thought about trying that but there only being one prefab file for evergreens really threw me off. Now that I look again I do see the "prefab_name="evergreen_sparse"" and related within the file which implies multifuctional use. The unfortunate part is that this doesn't innately return conditions like burnt so I'll need special checks for that. Two questions in one week both anwsered concisely. Absolutely love it. Thanks Penny! Edited January 15 by MakeSureToKnock 1 Link to comment Share on other sites More sharing options...
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