How to create a order in a table

Hello developers,

So i am trying to create a system that creates a table, where you can add words.

IDK how to explain but i give you examples:

local wordtable = {
	["words"] = {
		Cool = {Enum.KeyCode.Z},
		sick = {Enum.KeyCode.V}
	},
	["Troll"] = {
		Example1lol = {Enum.KeyCode.X},
		Welp12 = {Enum.KeyCode.B,}
	},
}

local table1 = {}

This is a example of 2 tables. I created a system that adds words from wordtable into table1. So i have 2 problems or 1. I want to create a way, to check what the parent from word is. So if i have Welp12, i want to get “Troll”. I also want to create a order, so if you need to use/get words in the correct order, but you can keep repeating to use from the same type (word, Troll). So an example would look like:

Troll, words

What you can say:

Example1lol, Welp12, Cool.

This will work, bc “Example1lol, Welp12” are both from Troll, and than you can say infinite words from words. So this would also be possible:
(4 times troll, than 3 times word, but its in good order so it will work)
Example1lol, Example1lol, Example1lol, Example1lol, Cool, Cool, Cool.

What wouldend be possible is:

Example1lol, Cool, Example1lol

This wouldend work bc, the order you use is “Troll”, “words”, “Troll” and not “Troll, words”

Does anyone know how i can create this, if you still don’t understabd feel free to ask.

Could anybody please help me with this, i am stuck here for a day.

Pretty confused on what you’re saying, but what you’ll want is table.sort().

table.sort() takes two arguments. The first is the table and the second is a sorting function. For basic alphabetical order, you’d do this:

local someTable = {'b','c','a'}
local sort = function(a,b)
	return a < b
end
table.sort(someTable,sort)
print(someTable)

a is the first variable and b is the compared variable (next). The reason a simple < statement works is because it’s comparable byte values. If you had a dictionary or were using instances instead, you can put a.PropertyName < b.PropertyName, or the reverse if you want the reverse.

oh, thats not the problem,

I am trying to create a system, where you need to press/say the correct words in the correct order, but every word has its type, so lets me explain more clearly

I have 2 tables, 1 with the words, and 1 with the words that you typed.

local wordtable = {
	["words"] = {
		Cool = {Enum.KeyCode.Z},
		sick = {Enum.KeyCode.V}
	},
	["EpicWord"] = {
		Imagine= {Enum.KeyCode.X},
		Nice = {Enum.KeyCode.B,}
	},
}

local table1 = {}


What i want to achieve is that, that you need to say the words from wordtable[“words”] first, with an unlimited amount, than when you say a word from wordtable[“EpicWord”], you cannot say (just give a false value) a word from wordtable[“words”], because that is before wordtable[“EpicWord”].

So lets say it eazier: if you say a word from the next “Type” (which is, Words and EpicWord) you can’t say the one before the epic word.

So:

order = 1
(order 1 = wordtable[“words”])
(order 2 = wordtable[“EpicWord”])

and if you say a word from wordtable[“EpicWord”], the order goes up by 1
(because the order from “EpicWord” is higher than that from “word”)
so you can’t say “word”.[Exampleword} bc you already said a word from a type that is higher than “word”

i hope this makes it more clear.

Try

local wordtable = {
	["words"] = {
		Cool = {Enum.KeyCode.Z},
		sick = {Enum.KeyCode.V},
		order = 1
	},
	["EpicWord"] = {
		Imagine= {Enum.KeyCode.X},
		Nice = {Enum.KeyCode.B,},
		order = 2
	},
}

Then save the data on what order of the word they said
afterwards, check:

if not wordtable[  (the word)  ] then
return end
if (the saved data) > wordtable[  (the word)  ].order then
	--do your stuff
end
1 Like

hmm, i want a different solution, that doesn’t work together with my other script. I know how a way to do this, but i can’t code it for some reason.

How to maby code:
creating a table that checks what table in wordtable[type] is possible and see if the [word] is inside that table, else do something.

A also i want to create to force someone to say a part of wordtable[type]. So you must say a word from “words”. If you don’t than you return false.