Hello everyone. Today I’m here with a little issue. So I’ve been working on another little project for a bit but I’ve been stuck. I need to find a way to make it so if for example,
if myWords == words…“.” Then
isTrue()
So basically if I write “Codea” it will say it Normally, but if I say “Codea.” With a full stop, it will restart or something. How can I do that? How do I check if there’s a full stop there. Is it possible?
function setup()
words = ""
dependables = {} -- dont worry about these
parameter.boolean("test")
end
function draw()
background(36, 36, 36, 255)
pushStyle()
font("Arial-BoldMT")
fontSize(25)
fill(0, 161, 255, 255)
textWrapWidth(WIDTH - 10)
text(words, WIDTH/2, HEIGHT/2 + 250)
end
function touched(touch)
if touch.state == ENDED then
showKeyboard()
end
end
function keyboard(key)
words = words..key
if key == BACKSPACE then
words = string.sub(words, 1, -2)
end
if key == RETURN then
sayWords()
end
if key == RETURN and words == words.."." then -- heres the problem
restart() -- test function if it works
end
end
function sayWords()
speech.language = "EN-GB"
speech.volume = 1.0
speech.say(words)
end
@LL_Phoenix456 Instead of searching thru words looking for a ., just compare key for a . and set a flag. If that flag is true, then do a restart after you sayWords().
str = "Hello World, and here comes the dot."
local d = string.find(str, "%.") -- We need a "%" before the dot, because a dot represents a class
if d then
-- We have a dot, do something
else
-- We don't have a dot, do something.
end
@dave1707, your idea would work as long as he doesn’t have backspaces, when he adds them to remove a letter, the flag will not be false. If he has two dots…
@LL_Phoenix456 - you need to read up on how string.find works, there are many pages describing it. Please do a little research before asking questions here.
@LL_Phoenix456 I’m not sure of the reason to look for the period when you press return to do a restart. Here’s a little example that lets you key whatever you want and when you press return it says what you keyed. It then clears the words variable and let’s you key something else. You can key as much as you want before pressing return.
displayMode(FULLSCREEN)
function setup()
words = ""
font("Arial-BoldMT")
fontSize(25)
end
function draw()
background(36, 36, 36, 255)
fill(0, 161, 255, 255)
textWrapWidth(WIDTH - 10)
text(words, WIDTH/2, HEIGHT/2 + 250)
end
function touched(touch)
if touch.state == ENDED then
showKeyboard()
end
end
function keyboard(key)
words = words..key
if key == BACKSPACE then
words = string.sub(words, 1, -2)
end
if key == RETURN then
sayWords()
end
end
function sayWords()
speech.language = "EN-GB"
speech.volume = 1.0
speech.say(words)
words=""
end