So first I'll need to explain the script. I'm trying to make a z-target camera system like in zelda. I have the camera system mostly done, the only thing I need now is to get a subject to target. So I made a module that gets sent(via bindable event) everything the player is touching and it puts them in a table. The item that the module gets sent is a table that holds the target item's data. This includes things like the position to move the camera its type(a value that's 1-5)ect. I want to sort the target choices based on their type. 1-5 1=boss, 2=enemy,3=NPC,4=Sign,5=other. The system will select the highest number type that is currently in range. That way you don't accidentally target an NPC when your in a fight. So the issue I'm having is sorting the tables based on type.
7 | for index, Table in pairs (options) do |
8 | table.insert(Class [ Table.Type ] , Table) |
I have Class as a table, and each type 1,2,3,4,5 are tables inside Class. In the for loop, options is a table that hold all of the tables that are sent through the bindable event. All the tables in options are things the player can target(I.e sign, NPC ect) type is the value that classifies what each object is(I thought of using strings but numbers would mean less if statements, I could just search for the highest available number). So once i put all of the objects in Class and in side their respective tables, I run a repeat loop with a variable called count.
5 | until count > = 5 or Class [ count ] ~ = nil |
count will tell me what part of class[1,2,3,4,5] has entries available. The problem is I don't know how to check if a class table is nil or not. If i check Class[count] it only check if class[count] is a thing, which 1-5 are tables. How would I check if inside Class[1] table or 2,3,4,5 is nil or not?
A bit more clarification::
so I'm putting values inside of Class[1,2,3,4,5] tables, any enemy that the player can target I'm putting their value inside Class[2] table. I'm trying to read the data thats inside the class tables. if i put
it's going to print "Not empty" even if there is nothing inside Class[1]. Because Class[1] is a table. So I'm trying to see if that table has anything inside of it.