Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is this script detecting words out of context?

Asked by
chrono2 189
8 years ago

This script is supposed to detect when a player says anything with the words "What", "He", and "Do", or "What", "It", and "Do", or "What", "You", and "Do".

However, while it does so just fine, it also detects "He", "It", and "You" in any context with or without the other words.

01        words = {
02--["Explain Function"]
03        words = {
04            {"What","It","Do"},
05            {"What","He","Do"},
06            {"What","You","Do"},
07        },
08                func = function( p ) -- functions go HERE
09            print(p.Name .. " asked Faraday to explain his function")
10            game.ServerScriptService.FaraVoice.Value = "Currently I am programmed to respond to certain phrases, however soon I will run this house."
11            wait(0.3)
12            local text = game.ServerScriptService.FaraVoice.Value
13            local y = game:GetService("Chat"):Chat(Interfaces, ""..text, Enum.ChatColor.Green) 
14        end
15}
View all 37 lines...

2 answers

Log in to vote
1
Answered by 8 years ago

You altered the code I gave you in a way that makes it work really differently. I don't really even know what your word sort algorithm results in. Anyways, I updated the same one I made you yesterday to do what you want.

Should be straightforward

01match = nil
02 
03phrases = {
04    ["Amour"] = {
05        words = {
06            {"Jarvis" , "Armour" , "pls"},
07            {"Jarvis" , "Armour"},
08            {"Jarvis" , "Give" , "Armour"} 
09        },
10        func = function( p ) -- functions go HERE
11            print(p.Name .. " activated armor function")   
12        end
13    },
14    ["Health"] = {
15        words = {
View all 73 lines...
0
Thanks for that. I basically just used your code as a template to make my own with some help from a friend, because I couldn't understand yours well enough to make it do what I wanted it to. I thought I PMed you about it, but I guess I was wrong. Anyway, thanks again! You're the reason this project is even possible. chrono2 189 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Please provide code with your answers. Simply posting an explanation does not help someone new to programming understand how to implement a concept programatically.
1function onChatted(message, recipient, speaker)
2    local actualRecipient = "Admin"
3    if recipient == actualRecipient then
4        --The rest of your code there.
5    end
6end

That's because it happens anytime when the player chats.

I believe the solution is for you to specify the recipient that should respond and if the recipient argument matches the variable, then the function executes.

The above code does that for you. You can paste your code within the if/then. If the recipient is the wanted recipient, then your function should check the words.

0
How would that change anything though? It works fine if I'm using only 2 word phrases, but when I put in a third it detects it without the other two. chrono2 189 — 8y

Answer this question