Making a global table is as simple as
Code:
if (CC_CLI == nil) then CC_CLI = {}; end
You could also define functions inside and outside of that block like
Code:
--expects a table
function populateWithActors(a,c)
c = c or 0;
for actor in MovableMan.Actors do --iterate all the actors
c = c + 1; --increment "count"
table.insert(a,actor,actor.PresetName .. count);
end
end
--pads a string to a set length with spaces
function padStringToLength(s,l)
local length = s:len()
if length > l then
s = s:sub(1,l);
elseif length < l then
s = s .. " ":rep(l-length);
end
return s
end
--initialising CC_CLI if needed
if (CC_CLI == nil) then
CC_CLI = {}; --set up a global table to hold everything
CC_CLI.count = 0; --start a count
CC_CLI.Actors = {}; --create a table for the actors
--populate the CLI's actor table with actors NOTE THIS IS ONLY VALID FOR THIS FRAME THINGS MIGHT DIE OR COME INTO EXISTANCE!
populateWithActors(CC_CLI.Actors, CC_CLI.count);
--this returns the first found actor with a string in its tag or nil if none is found
function CC_CLI.firstWithTag(a)
for k,v in pairs(CC_CLI.Actors) do
if type(k) ~= "string" then continue;
elseif k:find(a) ~= nil then
return v;
end
end
return nil;
end
--dumps tags, names, and positions in a visual table.
function CC_CLI.dumpAll()
print(padStringToLength("TAG",30) .. "|" .. padStringToLength("PRESETNAME",30) .. "|" .. padStringToLength("POS",15));
for k,v in pairs(CC_CLI.Actors) do
print(padStringToLength(k,30) .. "|" .. padStringToLength(v.PresetName,30) .. "|" .. padStringToLength(v.Pos:toString(),15));
end
end
end
for a semi-functional CLI. Feel free to expand it, I'd prefer credit to not but everything is only partially likely to work as I haven't done much CC-lua (or lua in general) for a long time. a way of updating the list wouldn't go astray, remember to clear it first.