Script to write script for a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Script to write script for a field
I am somewhat new to programming and LC. I am creating a stack that will have hundreds of cards. The first card will have a scrollable field (let's call it "index field") on which each subsequent card is listed and accessible by clicking on a link in the line that states its name. Righting the script in the script editor for the index field will be time-consuming and subject to transcribing errors. I would like to write a script that goes to the index field and gets the text that is linked and then goes to the text editor and puts it into the script of the field, gets the next linked text on the next line of the index field, goes to the script editor, etc., over and over again. For example, if a line in the index field contains the linked text "05-11-87" and the card to be created will have the name "05-11-87," the script will get the linked text in the index field, go the text editor, and write this:
on linkClicked myLink
case "05-11-87"
go cd "05-11-87"
break
and continue on for every line of the index field. It would be as through I could write a script in AutoHotKey that accesses the index field and the script of the index field, but I don't think that is possible. Is there any other way to automate the writing of the script?
Thanks
Monty
on linkClicked myLink
case "05-11-87"
go cd "05-11-87"
break
and continue on for every line of the index field. It would be as through I could write a script in AutoHotKey that accesses the index field and the script of the index field, but I don't think that is possible. Is there any other way to automate the writing of the script?
Thanks
Monty
Re: Script to write script for a field
Hi Monty,
I'm not 100% sure I understand what your'e after but thought I might give you another way to think about the problem.
Suppose you only used 2 cards.
Now, maybe you had a "05-11-87.txt" file (could be html,rtf, image, other)
All the text files were in a single folder.
Load the index cd
"put the files into fld 1"
"on mouseUp
put url("file:" & path\to\file & the selectedText of fld 1) into fld 1 of cd 2"
I'm going to stop there as I am probably way off track.
What do you think?
Simon
I'm not 100% sure I understand what your'e after but thought I might give you another way to think about the problem.
Suppose you only used 2 cards.
Now, maybe you had a "05-11-87.txt" file (could be html,rtf, image, other)
All the text files were in a single folder.
Load the index cd
"put the files into fld 1"
"on mouseUp
put url("file:" & path\to\file & the selectedText of fld 1) into fld 1 of cd 2"
I'm going to stop there as I am probably way off track.
What do you think?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 19
- Joined: Wed Jan 26, 2011 7:04 am
Re: Script to write script for a field
Hi Monty,
I think this is the kind of thing you're looking for
This will put the text you've selected in your scrolling field into a variable, then go to the card with the name of that variable. It's a slightly different solution to what you've asked for but shows off one of the things I love about livecode, the ability to use variables to identify cards and objects so you can avoid writing lines of code when working with lots of cards or objects.
I hope that helps.
Max
I think this is the kind of thing you're looking for
This will put the text you've selected in your scrolling field into a variable, then go to the card with the name of that variable. It's a slightly different solution to what you've asked for but shows off one of the things I love about livecode, the ability to use variables to identify cards and objects so you can avoid writing lines of code when working with lots of cards or objects.
Code: Select all
on mousedown
put the selectedtext of me into tCdname
go to card tCdname
end mousedown
Max
Re: Script to write script for a field
Hi.
I also am not sure what you need, but I expect that there is a more direct way to achieve it without modifying the scripts of objects on the fly.
That said, know that the script of an object is a property of that object. So you can "set the script of button 1 to someHandler" where someHandler might contain the text:
on mouseUp
beep 3
end mouseUp
Scripts are not containers. You cannot "put" the above code into a script, you must set its "script" property to a value.
I suspect that I am as far off base as Simon thinks he is.
Craig Newman
I also am not sure what you need, but I expect that there is a more direct way to achieve it without modifying the scripts of objects on the fly.
That said, know that the script of an object is a property of that object. So you can "set the script of button 1 to someHandler" where someHandler might contain the text:
on mouseUp
beep 3
end mouseUp
Scripts are not containers. You cannot "put" the above code into a script, you must set its "script" property to a value.
I suspect that I am as far off base as Simon thinks he is.
Craig Newman
Re: Script to write script for a field
Thanks Simon, MaxDangerMouse, and dunbarx for your responses. I think MaxDangerMouse understood best what I am trying to do. I mistakenly thought that I could only use the linkClicked message to navigate from a list field to a particular card. If that were the case, in the script of the list field I would have to use hundreds of switch control structures, and therefore thought I needed a script to write the long script containing the switch control structures. Following MaxDangerMouse's suggestion, it looked as though I could use the selectedText function and use his four lines of code by which to navigate to one of hundreds or thousands of cards. Cool solution! Question: how do you select just a chunk of a line in a field, such as the first word, by clicking on it. When I tried do that, all I did was put the insertion point into the word and the word was not selected. It seemed as though the user would have to double-click or click and drag to select the chunk and then click on a button that used the selectedText function. Not what I want for the user, and when I wrote such a script, nothing happened. However, when I set the listBehavior property of the field to true, clicking on a line selected the entire line and navigated to the corresponding card if the card had the same name as the text of the selected line. Can a user just select one word of a line and automatically go to a card with the same name of the word selected? If so, how? If the user cannot navigate by selecting a single word, then the solution seems to be setting listBehavior to true and property naming the cards.Thanks to you all for your help.
Monty
Monty
-
- Posts: 19
- Joined: Wed Jan 26, 2011 7:04 am
Re: Script to write script for a field
Hi Monty
I'm assuming the first word in each line is the same as the name of the card that you're hoping to go to. In that case:
Here's a link to an example stack of what you're talking about https://onedrive.live.com/redir?resid=B ... c.livecode
Thanks
Max
I'm assuming the first word in each line is the same as the name of the card that you're hoping to go to. In that case:
Code: Select all
on mousedown
put the selectedtext of me into tCdname
put word 1 of tCdname into tCdname
go to card tCdname
end mousedown
Thanks
Max
Re: Script to write script for a field
If the field is editable, you will not get a mouseUp message. If the locktext is true, you will. So just set the locktext to true, the autohilite to false, and the traversalOn to false.
Once that is done, the user can click in the field. You can capture the text in different ways:
In a list field, the entire text of the line is the clickText.
In a non-list field, the text under the mouse (usually a word) is the mouseText, and if clicked, the word is the clickText.
If a selection is present (in a locked field, a script would have selected that) then you can get the selectedText
If the text has a textstyle of "link" then the entire text of the link is the linkText.
If your text is static, I would set the textstyle of the text that is the card name to "link". You can turn off the underline if you don't want it (though the underline gives the user information that they can click it.) Set the underlineLinks to false if you don't want it. Another advantage of using link text is that you will get a special message when the user clicks it: linkClicked. That is the message I would catch. It passes a parameter that contains the text of the link, so you will only need this handler:
Once that is done, the user can click in the field. You can capture the text in different ways:
In a list field, the entire text of the line is the clickText.
In a non-list field, the text under the mouse (usually a word) is the mouseText, and if clicked, the word is the clickText.
If a selection is present (in a locked field, a script would have selected that) then you can get the selectedText
If the text has a textstyle of "link" then the entire text of the link is the linkText.
If your text is static, I would set the textstyle of the text that is the card name to "link". You can turn off the underline if you don't want it (though the underline gives the user information that they can click it.) Set the underlineLinks to false if you don't want it. Another advantage of using link text is that you will get a special message when the user clicks it: linkClicked. That is the message I would catch. It passes a parameter that contains the text of the link, so you will only need this handler:
Code: Select all
on linkClicked pLink
go card pLink
end linkClicked
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Script to write script for a field
The code of MaxDangerMouse has solved my problem about clicking on a line in a list field and going to a card of the same name as the selected line, but now I have a problem related to clicking on a button or image in a background group on multiple cards in a stack in order to open a different pdf document linked to each card. If the card and the document have the same name, the only way I see is to use the name property of each card:
on mouseUp
Put the name of this card into tcdname
launch document "path/to/document/"&tcdname&".pdf"
end mouseUp
But nothing happens. When I use the Answer command to check the contents of the variable tcdname, I see "card 'name of card.'" Is the word "card" part of the name? That would explain it, but I doubt think "card" is part of the contents. There is something missing in my script that I don't know about. Any suggestions would be very much appreciated. Can't find any discussion on this forum.
Monty
on mouseUp
Put the name of this card into tcdname
launch document "path/to/document/"&tcdname&".pdf"
end mouseUp
But nothing happens. When I use the Answer command to check the contents of the variable tcdname, I see "card 'name of card.'" Is the word "card" part of the name? That would explain it, but I doubt think "card" is part of the contents. There is something missing in my script that I don't know about. Any suggestions would be very much appreciated. Can't find any discussion on this forum.
Monty
Re: Script to write script for a field
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!