Text fields not displaying entered text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
laurawoods
Posts: 1
Joined: Fri Apr 05, 2024 3:22 am
Contact:

Text fields not displaying entered text

Post by laurawoods » Fri Apr 05, 2024 3:27 am

Code: Select all

on mouseUp
   put "Enter your name:" into field "nameField"
   -- Prompt user for input
end mouseUp

on enterKey
   put empty into field "responseField"
   put "Hello" && field "nameField" && "!" into field "responseField"
   -- Display a greeting using entered name
end enterKey
The text fields don't display any text when I type. I've checked the object properties and they seem correct. What could be causing this issue?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Text fields not displaying entered text

Post by Klaus » Fri Apr 05, 2024 11:08 am

Hi Laura,

welcome to the forum!

Some questions:
1. Where did you place the script that you posted above?
2. It is not clear where your user(s) need to enter their name!

I would recommend something like this...
Create a button "Enter your name" or something with this script:

Code: Select all

## This will open a dialog box where the user can enter its/her name
on mouseUp
   ## the ASK and ANSWER dialog will be open until the user clicks "OK" or "Cancel"
   ask "Enter your name:"

   ## The text entered by the user will get placed into the variable IT
   put "Hello," && it & "!" into tGreetings
   
   ## Now you can put this into a field
   put tGreetings into fld "nameField"

   ## Or show another dialog:
   answer tGreetings
end mouseUp
Best

Klaus

P.S.
Personal not:
A little "Hello" or something would not have hurt for the very first posting!

stam
Posts: 2688
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Text fields not displaying entered text

Post by stam » Fri Apr 05, 2024 12:03 pm

Great task for new users of liveCode and for current users this is straightforward.

I thought I'd ask ChatGPT how to do this, to see where it's at with LC.

I asked ChatGPT :

Code: Select all

create livecode script that asks user for their name and then generates a phrase "Hello <name>" in a field
This is its considered response!
Open LiveCode and Create a New Stack: Start by opening LiveCode. In the LiveCode IDE, create a new stack by going to File > New Stack > Default Size. This will be your main working area for the script.

Add a Button to Your Stack: From the Tools palette, select the Button tool and draw a button on your stack. This button will trigger the action of asking the user's name and then greeting them.

Add a Field to Your Stack for Displaying the Greeting:
From the Tools palette, select the Field tool (it might look like a T or an A, depending on your version of LiveCode).
Draw a text field on your stack. This field will be used to display the greeting message.

Name the Field for Easy Reference:
With the field still selected, open the Property Inspector. You can do this by right-clicking on the field and selecting "Property Inspector" or by simply double-clicking on the field.
Go to the General tab and find the Name property. Give your field a meaningful name, like greetingField. This makes it easier to reference in your script.

Code the Button to Ask for the User's Name: Double-click on the button you just created to open the Button Inspector. Go to the Script tab to write your LiveCode script. Enter the following code:

Code: Select all

on mouseUp
   ask "What is your name?" with ""
   if it is not empty then
      put "Hello, " & it into field "greetingField"
   else
      put "Hello, stranger!" into field "greetingField"
   end if
end mouseUp
Not bad - while I have seen errors with LC scripts generated with AI previously, this is definitely improving.

It reads like a clear tutorial, and will probably be a useful too for speeding up learning...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”