writing multiple lines of script via message box

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
JFic1
Posts: 2
Joined: Wed Dec 31, 2014 2:16 pm

writing multiple lines of script via message box

Post by JFic1 » Wed Dec 31, 2014 10:58 pm

I'm just getting used to LiveCode. I love the possibility of fast live testing because instant feedback is a great way to learn.

From Python's IDLE, I'm really hooked on writing single lines but also multi-line functions using a command line interface.

Can I do the same with LiveCode? I know that the script editor is great and has debugging features, but hopefully you can indulge me as I ease my way into LiveCode. It's going to take a while before I get used to all of the floating toolbars. The more I can do with just the message box, the happier I'll be in the beginning!

Really specifically, because I'm just starting, I'm trying to create Hello World using just the message box.

Ideally, I could say:

Code: Select all

create button
set script of button 1 to 
"
on mouseUp
[indent]answer /"Hello World/"[/indent]
[indent]end mouseUp[/indent]
"
Here's what actually works, as far as I can tell:

Code: Select all

create button
set script of button 1 to "on MouseUp"
I can confirm I've done something via the message box by typing:

Code: Select all

put line 1 of script of button 1

The line I'd want to write next is complicated by at least two things:

1) I don't know how, if it's possible, to indicate in the message box that I'd like "answer" to be at the start of a new line in the button's script. Putting the message box into multi-line mode and submitting on multiple lines didn't work. I think it didn't like my attempting to open the quotes on one line and close them on another. This forum post (http://forums.livecode.com/phpBB2/viewtopic.php?t=2767 ) gave me some slight hope that using HTML tags to indicate line breaks or paragraphs might work, but no luck. If there's a message box syntax for setting or adding to line 2 of the script, I don't know it.

2) I also wouldn't know how to do a quote within a quote, as would be necessary for "Hello World." Using a forward slash as an escape character didn't work.

Any help with the above would be appreciated.

Just to put everything in context, I assume it's not vital to be able to do all of this via the message box, and I'm looking forward to using the script editor more soon. I'm just at a phase now where I'm curious about how far I can go with the message box. Hopefully you'll indulge my curiosity!

uelandbob
Posts: 72
Joined: Mon Dec 29, 2014 3:28 pm

Re: writing multiple lines of script via message box

Post by uelandbob » Wed Dec 31, 2014 11:21 pm

Hi I'm new to LC as well,

Try this

1. create two cards. On card 2 make a field called hiddenField (or something like this) that you can hide and inside it enter
on mouseUp
answer "Hello world"
end mouseUp

2. Then in the message box write
create button
set script of button 1 to field hiddenField of card 2

Of course you don't need two cards, you can do it on one card just make sure to hide the field so it doesn't clutter your card.
I'm sure there are better ways, but I've seen this technique of hiding things used by others.
Last edited by uelandbob on Thu Jan 01, 2015 12:10 am, edited 1 time in total.
uelandbob@gmail.com

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: writing multiple lines of script via message box

Post by SparkOut » Wed Dec 31, 2014 11:58 pm

The multiline message box won't work quite like that, but I believe you can:

set the script of button "btn1" to "on mouseUp" & cr & "answer" && quote & "Hello World" & quote & cr & "end mouseUp"

although... I really think it's easier to use the IDE :D

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

Re: writing multiple lines of script via message box

Post by dunbarx » Thu Jan 01, 2015 10:18 pm

Hi.

What Sparkout said.

Perhaps coming from another language, your thinking is being colored. If I were to advise a new user how to start learning the ins and outs of LC, I would have that person create a field or two and a button or two, and start writing handlers directly into the scripts of those controls.

The message box is skittish and hard to nail down to a certain extent. I advise staying firmly on the card, where everything stays put, and you can work both with and inside familiar objects directly. The idea of creating and modifying script properties "remotely" is often quite useful, but inappropriate for a new user. Totally inappropriate.

Write back early and often, I would try to make an address book or a calendar. These utilities may well be discarded once you are done with them, but the effort to make them just the way you want to may in fact never end, and you will never be done with them. This is a good thing.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: writing multiple lines of script via message box

Post by FourthWorld » Fri Jan 02, 2015 12:07 am

JFic1 wrote:Really specifically, because I'm just starting, I'm trying to create Hello World using just the message box.
You can run the answer command right in the Message Box:

Code: Select all

answer "Hello World"
The Message Box is handy for a lots of small things, but when you want code in an object the script editor is a better tool for that.

While it's possible to dynamically set scripts, in practice it's rarely done because LiveCode provides simpler and faster means of dynamically changing behavior.

This article may help get you started, a brief overview of the LiveCode message path and ways to extend and modify it:
http://fourthworld.com/embassy/articles ... _path.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: writing multiple lines of script via message box

Post by jacque » Fri Jan 02, 2015 7:45 pm

Using the message box exclusively to create a working stack will be an exercise in frustration. There's so much that can go wrong with this method, and it will, at minimum, triple the amount of work needed to produce an app. Until you know LC very well, I'd avoid this approach.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: writing multiple lines of script via message box

Post by Martin Koob » Fri Jan 02, 2015 8:06 pm

A useful thing I found a while ago is that if you want to string a few commands in the message box you can use semicolons to separate what would be lines of code in a multiline script.

You can have variables persist.

Code: Select all

put "Hello" into tGreeting; put "world" into tAudience; answer tGreeting && tAudience & "!"
You can have repeat loops.

Code: Select all

put "Hello" into tGreeting; repeat for 3; put "world" into tAudience; answer tGreeting && tAudience & "!"; end repeat
or conditionals

Code: Select all

put "Hello" into tGreeting; ask "Audience?"; put it into tAudience; if tAudience is "world" then ; answer tGreeting && tAudience & "!"; else; answer "good bye" && tAudience; end if
If you are in the midst of stepping thru code in the debugger you can access the current values of variables in the script.

Martin

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: writing multiple lines of script via message box

Post by Martin Koob » Fri Jan 02, 2015 8:24 pm

2) I also wouldn't know how to do a quote within a quote, as would be necessary for "Hello World." Using a forward slash as an escape character didn't work.
To put a quote in a string you use the constant 'quote' and concatenate it with your other strings in quotes with the '&' operator.

Code: Select all

put quote & "Hello world!" & quote into tString 
To do lines of a script you need to separate them with the constant 'CR' (carriage return)

So using semicolons and the constant 'quote' and the constant 'CR' you can create a "Hello world" button using the message box. You can even click on the button from the message box.

Try this in the message box.

Code: Select all

create button "hello"; set the script of button "hello" to  "on mouseUp" & CR & "answer" & quote & "Hello world!" & quote & CR & "end mouseUP"; send "mouseUp" to button "hello"
Not a really useful thing but a good way to see what the message box can do.

Martin

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: writing multiple lines of script via message box

Post by jacque » Fri Jan 02, 2015 8:41 pm

A useful thing I found a while ago is that if you want to string a few commands in the message box you can use semicolons to separate what would be lines of code in a multiline script.
It's a handy trick that dates way back to MetaCard and I used to do that all the time. But it doesn't always work in LiveCode, so mileage may vary. I haven't quite pinned down what causes the failures yet, it's inconsistent.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

JFic1
Posts: 2
Joined: Wed Dec 31, 2014 2:16 pm

Re: writing multiple lines of script via message box

Post by JFic1 » Fri Jan 02, 2015 9:36 pm

Thanks, everyone! Great to have such a supportive community. Thanks to you, I got it to work!

Now that I've had my fun, I'll probably start using the script editor like everyone else, but I do feel more comfortable knowing that the message box can be quite powerful. (Note taken, though, that it can also be inconsistent. I'll have to watch for that.)

Happy new year!

Post Reply