Program Button Script Programically
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Program Button Script Programically
Before I posted this, I have been searching the forums and google to find examples of how to program a button on a card within the openCard script of the card instead of adding the script to the button as this specific button would need to change the script depending on the user's interaction with the card.
The dictionary of LC editor's example was not very good as it only showed how to empty the button's script. I would like the script to be if the environment is development, then replace the script button with something totally different then if the application was ran on a standalone and the button is to quit the application.
If someone has a resource already online, let me know where an example is located at so I can continue my Livecode Learning Process.
The dictionary of LC editor's example was not very good as it only showed how to empty the button's script. I would like the script to be if the environment is development, then replace the script button with something totally different then if the application was ran on a standalone and the button is to quit the application.
If someone has a resource already online, let me know where an example is located at so I can continue my Livecode Learning Process.
---
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Program Button Script Programically
Can you describe how much the code might vary in response to the user interaction? There are many ways this could be done, including changing the behavior object assigned to the button, and probably wouldn't require actually changing the button's script. But to know which method would be best in your circumstance it'll be helpful to know what those changes would entail.
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: Program Button Script Programically
Hi Graham,
there are limits on creating scripts "on the fly"!
But we have "behaviors"!
I would recommend to script a couple of behaviors and
set the behavior of your special button to one of these
depending on your needs.
Example, presuming the behavior buttons are on teh same card:
You get the picture
Best
Klaus
there are limits on creating scripts "on the fly"!
But we have "behaviors"!

I would recommend to script a couple of behaviors and
set the behavior of your special button to one of these
depending on your needs.
Example, presuming the behavior buttons are on teh same card:
Code: Select all
on opencard
if this_or_that then
set the behavior of btn "your special button here..." to the long ID of btn "behavior1"
else
set the behavior of btn "your special button here..." to the long ID of btn "behavior2"
end if
end opencard

Best
Klaus
Re: Program Button Script Programically
In the first application I am working on in Livecode as a Port of Adobe Flex/Air, I have a custom card that will display error messages within the application to make them "Pretty" instead of the answer box. This card called Alerts has 3 buttons at the bottom. The righthand is called Cancel_Button and if "the patform" does not equal the platforms which the application has been written for, this Cancel Button has been changed to Quit.
By default the onMouseUp of the Cancel Button will send the user to the Main Card of the stack. But in this case, it would need to detect if the environment is development or standalone. If it is development then do nothing. But if it is standalone then quit the application.
By default the onMouseUp of the Cancel Button will send the user to the Main Card of the stack. But in this case, it would need to detect if the environment is development or standalone. If it is development then do nothing. But if it is standalone then quit the application.
FourthWorld wrote:Can you describe how much the code might vary in response to the user interaction? There are many ways this could be done, including changing the behavior object assigned to the button, and probably wouldn't require actually changing the button's script. But to know which method would be best in your circumstance it'll be helpful to know what those changes would entail.
---
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Program Button Script Programically
Hi Graham
It sounds like you just need a simple if statement making use of the 'environment' function - something like:
It sounds like you just need a simple if statement making use of the 'environment' function - something like:
Code: Select all
on mouseUp
if the environment is "development" then
--do nothing
else
--code to quit your app
end mouseUp
gpearson wrote:It would need to detect if the environment is development or standalone. If it is development then do nothing. But if it is standalone then quit the application.
"...this is not the code you are looking for..."
Re: Program Button Script Programically
I can do that if the button would always be the same but when I get to the section of the SQLite database, this button might need to be used to email developer of an error so its code will change along with the label of the button for this card.
I think right now, I might just create other buttons with the proper code, and position them where I need them to be along with making them visible or not.
I think right now, I might just create other buttons with the proper code, and position them where I need them to be along with making them visible or not.
---
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
Graham Pearson
Goshen, IN USA
We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Program Button Script Programically
Hi Graham
Yep having different buttons and showing/hiding them as required would work - but it might be simpler to just write the code in a single button! (reading results from SQLite queries etc and branching to different actions as a result?)
Kind regards
Dave
Yep having different buttons and showing/hiding them as required would work - but it might be simpler to just write the code in a single button! (reading results from SQLite queries etc and branching to different actions as a result?)
Kind regards
Dave
"...this is not the code you are looking for..."
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Program Button Script Programically
would this help?
then just set the label of the button in the opencard script?
Code: Select all
if the label of me is "whatever" then
do "whatever" stuff
else
do Some Other stuff
end if