Nwebie with scripting question

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MikeinHawaii
Posts: 90
Joined: Mon Jan 18, 2010 10:53 am

Nwebie with scripting question

Post by MikeinHawaii » Thu Jan 21, 2010 6:49 am

I am just starting out in transcript so please bear with me.. Can somebody please tell me how to script this situation?
I want to populate a card with 3 fields. The goal is to be able get the third field to show the result of the sum of any random numbers put into field one and field two. I have tried all sorts of combinations of script lines but keep getting error messages when I hit compile. Basically, I have given each field a name in the object inspector, and then my script goes something like this

Code: Select all

function "GetSum" of field1+field2.  Put result of Sum into field3
. Please forgive my ignorance of how to perform this, I never wrote any code in my life yet.

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

Re: Nwebie with scripting question

Post by FourthWorld » Thu Jan 21, 2010 7:11 am

I appreciate your posting that, Mike. Those of us who teach RevTalk for a living benefit tremendously from learning how newcomers envision how it works, where they guess right and where they guess not so right. :)

In your program, assuming you want to have the third field anytime the user exits either of the first two, put this in your card script:

Code: Select all

on closeField
   put fld 1 + fld 2 into fld 3
end closeField
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MikeinHawaii
Posts: 90
Joined: Mon Jan 18, 2010 10:53 am

Re: Nwebie with scripting question

Post by MikeinHawaii » Thu Jan 21, 2010 8:21 am

Perfect. Thank you very much. It never dawned on me that it would be a card script I needed to use. I kept trying to assign my scripts to the fields.

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

Re: Nwebie with scripting question

Post by FourthWorld » Thu Jan 21, 2010 12:46 pm

The good thing about Rev is that there are so many ways to do things. The bad thing about Rev is that there are so many ways to do things. ;)

Here, the advantage of putting the script at the card level is that you can affect two objects with one script. If you need a specific behavior for just once object, putting the script in that object is just fine, but when you need a behavior for multiple objects, you can choose any other point along the message path to expand the scope of objects it will affect.

While focused more on the basics of the message path than making effective scoping decisions using it, this article may be helpful:

Extending the Runtime Revolution Message Path:
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in Runtime Revolution's RevTalk Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply