Hello, im making a little AI boi and im making table/dictionary (I really dont know the the difference) of words, but for some reason when I try to get a table/dictionary in the table/dictionary it returns nil saying “Table Expected Got Nil”. Please help
Code:
local intents = {
greeting = {
patterns = “hi”, “how are you”, “hello”, “good day”, “whats up”;
responses = “Hello”, “Good to see you again”, “Hey”, “Hi”;
context_set = “”
}
}
for intent in pairs(intents) do
for pattern in pairs(intent["patterns"]) do --// Errors here
print("E")
end
end
no, I want to loop through all, Intent is = greeting when it loops wont make a difference. I have done prints and it works but it keeps saying pattern is not table and is nil. I think it may be since it still thinks its a string?
local intents = {
greeting = {
patterns = {"hi", "how are you", "hello", "good day", "whats up"};
responses = {"Hello", "Good to see you again", "Hey", "Hi"};
context_set = {""}
}
}
for _,intent in pairs(intents) do
for _,pattern in pairs(intent["patterns"]) do
print("E")
end
end
I only added _, before the variable in the for loops and it seems to work for me.
local intents = {
greeting = {
patterns = {"hi", "“how are you”", "“hello”", "“good day”", "“whats up”"},
responses = {""," “Good to see you again”", "“Hey", "“Hi”"},
context_set = {""}
}
}
for intent in ipairs(intents.greeting.patterns) do
print(intents.greeting.patterns[intent])
end
This works. I would always suggest you to use ipairs when iterating through arrays