Hello! How could I go about making a wpm (words per minute) calculator? When a player types in a textbox, I want to calculate the wpm.
Listen for when the text in the TextBox is changed (using the GetPropertyChangedSignal event). Store the previous text, and once a new word is added (check if it’s seperated by a space), add it to a count of words. Then take the total seconds that were spent typing so far, convert them into minutes, and divide the number of words by that amount — there you have your WPM.
How would I check if a new word is added?
Well, every time the text is changed, you can use string.split() with a space as the split to get a table with all the words in it.
Wouldn’t I have to use metatables then?
Well I don’t see why you would… The main thing you have to deal with is making sure they’re real words instead of things like “hey i , im typing so ma n y w o rds” in order to trick the wpm system by spamming spaces, which you can do with a couple of checks.
Well I’d want them to type a paragraph that’s already been given for them.
Then can’t you get how many words they typed in total and then divide that by how many minutes it took? For example, if the paragraph I had to type was 260 words and I took 3.4 minutes to write it, I would do 260 / 3.4 and the result would be around 76 wpm
(Of course if you want to correct mistakes as they’re being written, etc, you would probably have to use another method such as string.match or string.split to test if the words and punctuation line up correctly. You would have to do more research on those though, because I haven’t used them in a while)
https://developer.roblox.com/en-us/api-reference/lua-docs/string
Usually tests are over the course of a document or passage to allow for varied words and sentence structures. This gives the most generally applicable WPM.
Then you can just compare output with the original passage and dock points (speed) for errors; this wouldn’t be the case if you want WPM for active chatting.
The easiest solution I can think of, would be to add a finish special key that wouldn’t be used in the source. E.g. \ or `
Something that can be pressed quickly and let the computer do the calculations using total typed text once at the end. Using a first key stroke as the timer start event.
For unprepared (no source material) tests, you would need to use a lexicon* to cross reference.
*Lexicon (linguistics) - the complete set of meaningful units in a language.
Variables… There was no need to bump an old topic…
when they start typing. start the time. split the string by spaces into an array then do
#words_array/time
its very simple
the time limit is 1 minute
and lets say the player wrote 50 words, so just simply get the words the player wrote and write WPM next to it. it would simply be 50 words Per minute
this is the system all games/websites of wpm use for 1 minute limit