using functions and a good tutorial?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 19
- Joined: Wed Jun 18, 2014 7:23 pm
using functions and a good tutorial?
Hello, I have another question.
How do you go about using functions in livecode? I have an if statement where is a boolean is true then one function is called, and if the boolean is false a different function is called. However this code wont work. Both functions just contain if statements that will put a variable into a field. Pretty much all I want to do is add code that will initiate a function, and then the code in the function is executed. No values need to be passed between procedures or anything.
also are there any good livecode tutorials around? I would prefer youtube videos if possible. I have tried to watch the livecode academy video but it is too long to sit through.
Thanks for any help.
How do you go about using functions in livecode? I have an if statement where is a boolean is true then one function is called, and if the boolean is false a different function is called. However this code wont work. Both functions just contain if statements that will put a variable into a field. Pretty much all I want to do is add code that will initiate a function, and then the code in the function is executed. No values need to be passed between procedures or anything.
also are there any good livecode tutorials around? I would prefer youtube videos if possible. I have tried to watch the livecode academy video but it is too long to sit through.
Thanks for any help.
Re: using functions and a good tutorial?
Open Livecode, go to Help -> User Guide, it will open a big PDF file (more than 300 pages) with all the information you are looking for.
Moreover it is also on line at: http://www.scribd.com/doc/133073862/LiveCode-User-Guide
Moreover it is also on line at: http://www.scribd.com/doc/133073862/LiveCode-User-Guide
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: using functions and a good tutorial?
Have you checked out Chapter 5 in the User Guide? There's some good background on functions there.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: using functions and a good tutorial?
When I started programming, this is one of those subjects that for me was a "sudden click" moment that brought everything together. For that reason I thought I would try to explain it in terms that I would have better understood at that time.Unfortunately that is easier said than done. None the less, here is my attempt at being all teachery (new word I just made up. deal with it. Programmers are allowed to do that)
There are two basic structures for creating custom reusable code, the handler and the function. The handler is the simplest. It is done by simply defining a section within the script with "on" and a name. like so:
This handler can then be called by its name:
A function is a bit more fun. It is generally passed values when it is called, and returns a new value. Here is an example:
The structure starts with the word function, then the name you choose for your function followed by the names of variables that will store any data to be passed to the function when it is being called. It should have a "return line that determines what value the function call will actually represent, and finally an end line. An example of how you might call this function is as follows.
This would put 9 into a variable named tResult. Of course there is no need to write such a function as this example since it is built into LC, but I think it serves to show the basic structure.
another example:
In this example the number values contained in the variables tFirstNum and tSecondNum are added and put within the field "myField".
Now that i look at it, my attempt to be simple might be just confusing, but it really is a very simple concept. I promise.
Here is a homework assignment. Write a function that returns the average of a list of numbers. Do not use the built in averaging functions in LC (only use addition and division)
There are two basic structures for creating custom reusable code, the handler and the function. The handler is the simplest. It is done by simply defining a section within the script with "on" and a name. like so:
Code: Select all
on myHandlerName
stuff i want the handler to do
more stuff
etc.
end myHandlerName
Code: Select all
if blah blah blah
then
myHandlerName
end if
Code: Select all
function addMyNumbers tX tY
return tX+tY
end addMyNumbers
Code: Select all
put addMyNUmbers(6,3) into tResult
another example:
Code: Select all
set the text of field "myField" to addMyNumbers(tFirstNum,tSecondNum)
Now that i look at it, my attempt to be simple might be just confusing, but it really is a very simple concept. I promise.
Here is a homework assignment. Write a function that returns the average of a list of numbers. Do not use the built in averaging functions in LC (only use addition and division)
Re: using functions and a good tutorial?
Here's an article I wrote to explain functions:
http://hyperactivesw.com/resources_function.html
But from your description it doesn't sound like that's what you need. I think you only need a plain handler.
http://hyperactivesw.com/resources_function.html
But from your description it doesn't sound like that's what you need. I think you only need a plain handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 19
- Joined: Wed Jun 18, 2014 7:23 pm
Re: using functions and a good tutorial?
wow thank you so much everyone (especially magice). I didn't even realize that handlers existed
I will read over those documents you guys posted aswell.
