1 comment

  • Abbey Desjarlais

    Hi Jack,

    I've created an example that takes two numbers from the user, multiplies them together, then displays the result.


    <!-- Section 1 -->
    <section name="section1">
    <title>Inputs to an Equation</title>

    <!-- Create variables for the numbers you want entered and calculated -->
    local length = 0
    local width = 0
    local area = 0

    <!-- Create text boxes and labels describing what to input -->
    <p>Enter the length here:</p>
    <textField name="lengthInput" />

    <p>Enter the width here:</p>
    <textField name="widthInput" />

    <!-- On button click, the numbers entered in the text boxes are assigned to variables, then the area is calculated and output to a paragraph -->
    <button content="Calculate Area">
    length = tonumber(lengthInput.Text)
    width = tonumber(widthInput.Text)
    area = length*width
    outputPar.Text = string.format("Area = %.2f", area)

    <p name="outputPar">
    Area =


    The only tricky thing to remember when using textFields is that the field expects the user to enter text, not numbers, so we need to convert the input text to a number value using the "tonumber" function (e.g. tonumber(lengthInput.Text)).

    Comment actions Permalink

Please sign in to leave a comment.