How Do I Make a Simple Button Show a Message?

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
vidor636
Posts: 1
Joined: Tue May 27, 2025 9:59 am
Contact:

How Do I Make a Simple Button Show a Message?

Post by vidor636 » Tue May 27, 2025 10:05 am

I'm completely new to LiveCode and just started exploring it after seeing how beginner-friendly it claims to be. I'm following some tutorials, but I wanted to try something on my own to understand the basics better.

Right now, I'm trying to create a super simple app where I press a button, and it shows a message like "Hello, world!" in a popup. I added a button to my card, but I'm not sure where or how to write the code to make the message appear.

Could someone please walk me through:
  1. Where exactly do I write the script?
  2. What is the correct code to show a basic popup message?
  3. Any tips on how to test and make sure it's working?
Thanks so much in advance! Looking forward to learning more and building small projects as I go.

Klaus
Posts: 14189
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How Do I Make a Simple Button Show a Message?

Post by Klaus » Tue May 27, 2025 10:24 am

Hi Vidor,

by switching the TOOL in the "tools" palette, see screenshot, you can easily switch between RUNTIME and EDIT "mode".
Using the left tool (the runtime tool) you can test your stack like an enduser of your (later) app will experience it.

With the right tool (the EDIT tool), the arrow with the little cross, you can add new controls (buttons, fields etc.) and also write scripts
for all of your objects on the card:
Bildschirmfoto 2025-05-27 um 11.10.35.png
Bildschirmfoto 2025-05-27 um 11.10.35.png (7.99 KiB) Viewed 2913 times
Do this:
Click the EDIT tool in the palette, then RIGHT-CLICK on your button and select "Edit script" in the popup-menu:
Bildschirmfoto 2025-05-27 um 11.11.14.png
Bildschirmfoto 2025-05-27 um 11.11.14.png (17.55 KiB) Viewed 2913 times
Then the SCRIPT WINDOW will appear and you can write your script.
See a list of available hanlder for this object in the list on the left.
Click on "mouseup" and the so far empty handler will appear on the right side in the window.
Now add this:

Code: Select all

on mouseup pMouseButton
   ## This marks a comment, so you can add comments to your script 
   ## to know later what you have been doing here :-)
   
   ## The following line is the actual script that will open a dialog window with your string and an OK button
   answer "Hello Vidor!"
end mouseup
This will open a new window, a modal dialog, where you need to click on "OK" to make it diappear again.
Congrats you wrote your first working script. :-)

Here you can find more infos and tutorials:
https://lessons.livecode.com

Best from germany

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10315
Joined: Wed May 06, 2009 2:28 pm

Re: How Do I Make a Simple Button Show a Message?

Post by dunbarx » Tue May 27, 2025 2:57 pm

Hi.

Everything Klaus said.

But did you really mean "in a popup"? Klaus' handler will show a modal dialog. Another, similar possibility is to pull a new field from the tools palette, just like you did for that button. Then you could say, in that handler,

Code: Select all

put "Hello World" into field 1
And yet another way is to already have such a field, but which is currently hidden. Then you could:

Code: Select all

show field 1
I am merely introducing a few simple idea for you to think about and play with.

But those still are not a"popup". Are you sure you are using that term correctly?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: How Do I Make a Simple Button Show a Message?

Post by richmond62 » Tue May 27, 2025 9:20 pm

I looked up 'Display "Hello World" in a popup' and got a plethora of possibles of which the one that came up the most was a modal dialogue window.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: How Do I Make a Simple Button Show a Message?

Post by richmond62 » Tue May 27, 2025 9:33 pm

If you are working with MacOS you can display a substack as a sheet:
-
Screenshot 2025-05-27 at 23.31.11.png
-
Screenshot 2025-05-27 at 23.31.19.png
Attachments
My Stack.livecode.zip
Stack
(1.01 KiB) Downloaded 119 times

Post Reply