Writer, on 25 August 2014 - 12:04 PM, said:
what value is myEvent[2] ? Is it the char pressed?
Yes, it represents the char pressed -
assuming the captured event was a character event. If it's a key event, then it's the key code. If it's a mouse click event, then it's the button pressed.
Writer, on 25 August 2014 - 12:04 PM, said:
what does textField:sub(1, #textField-1) ? Is it diferent than string.sub?
Pretty much the same thing. textField:sub(1, #textField-1) functions the same as string.sub(textField, 1, #textField-1), but is ever so slightly shorter.
Writer, on 25 August 2014 - 12:04 PM, said:
the locals xPos and yPos, after the string has been decreased, does change?
They're only used to determine the position of the last typed character, so that a space can be written over it.
Writer, on 25 August 2014 - 12:04 PM, said:
why isn't name used in the first function?
It
is used in the first function.
Writer, on 25 August 2014 - 12:04 PM, said:
what does 'length' do in the first function?
It's used to determine the length of the text field - how many characters you can type into it at maximum.
Writer, on 25 August 2014 - 12:04 PM, said:
It returns a string which is equal to its first argument repeated an amount equal to its second argument.
For example, string.rep("asdf",3) returns "asdfasdfasdf". See
this page for more details on string-related functions.
Writer, on 25 August 2014 - 12:04 PM, said:
'#textFields[currentField].text<textFields[currentField].length'
"current length of the text in the text field < maximum allowed length of the text in the text field"
Writer, on 25 August 2014 - 12:04 PM, said:
'textFields[currentField].text = textFields[currentField].text .. myEvent[2]'
"let the text in the field equal the current text in the field plus whatever character the current char event represents".
Writer, on 25 August 2014 - 12:04 PM, said:
this one I never understood: what does 'for field,_ in pairs(textFields) do'? Like, what does 'field,_'? For what is it?
It starts a loop which repeats one time for every entry in the "textFields" table. The two variables, "field" and "_", each get assigned a table key and value respectively with each iteration.
"_" is generally used as a variable name when you don't care about the value in concern. I just wanted the key names. In this case, the first run of the loop might set the "field" variable to "Username", and the second might set it to "Password".
Pairs loops are generally used with tables specifically. You can read more about them in
this tables tutorial.
Writer, on 25 August 2014 - 12:04 PM, said:
what is the value of myEvent[3] ?
Usually nothing, but in the case of a mouse click event, it's the x-position where the click occurred. Compare my usage of "myEvent" to
this list.
Writer, on 25 August 2014 - 12:04 PM, said:
in the line where there if the last elseif, currentFields = field shouldn't be right under the for loop? Or does CC recognize it automaticaly?
The loop in concern checks each text field in the textFields table to see if a given mouse click event signifies a click on any of them. If it finds a match, then it sets clicked field as the "current" one which the user wants to type into, then breaks out of the search loop.