Script editor typing char by char

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: heatherlaine, Klaus, FourthWorld, kevinmiller

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Script editor typing char by char

Post by MaxV » Tue Aug 28, 2018 12:25 am

Hello,
I would make amazing educational videos about livecode, but I need these feature:

a button that clicking on it it takes the text in the clipboard memory (CTRL+C) and then put it in the current script editor page char by char as I were typing it. (I made a lot o misspelling typing, so I can't do in real time during recording the videos :oops: )
Any ideas to do it?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 1:39 am

Sure, give this a shot.

First, though, I wrote this in 6.5.2, to adjust for which ever IDE your using, open the message box and the script editor, move the mouse cursor over the script editor field, in the message box type

Code: Select all

"put the long name of the mouseControl"
You can edit what is returned however you like, I just used the whole string that was returned.

In the button of the stack you make for this, put

Code: Select all

put empty into field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" of stack "~/.runrev/livecodecommunity-6.5.2/Toolset/revscripteditor.rev" // put your returned long name here...
repeat for each character x in the clipboardData
   put x into field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" of stack "~/.runrev/livecodecommunity-6.5.2/Toolset/revscripteditor.rev" // put your returned long name here...
   wait for .25 seconds
   // if .25 seconds is too slow, lower it to .1 or even .05, or go to ticks...
end repeat
Name it with 'rev' in front of whatever name you like, and then save the file with a revYourFileName.rev extension, and drop it into your plugins folder :mrgreen:

*Edited for warning - BE CAREFUL!! This will copy the clipboard contents to whatever tab you have open, but it will empty that tab first. Before I hear about all the work you've lost using this, if you don't want to risk this kind of behavior, copy the contents to a variable, or remove the "put empty into field" parts before using.

You have been WARNED!!! :twisted:
Image

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 487
Joined: Fri Feb 06, 2015 4:03 pm

Re: Script editor typing char by char

Post by LiveCode_Panos » Tue Aug 28, 2018 8:05 am

Hi Max,

You might also find the "type" command useful.

Best,
Panos
--

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 10:25 am

Hmm. A new toy to play with! Thank you Panos :D

@Max, I expect to see a link in this thread to these amazing videos my friend :wink:
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2720
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Script editor typing char by char

Post by richmond62 » Tue Aug 28, 2018 10:59 am

Mind you, if you use type without setting the typingRate
to something a bit higher than the default 100 the effect is not really marked.
-
typingRat.jpeg
typingRat.jpeg (7.47 KiB) Viewed 407 times
-
typingRat

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 11:05 am

Also, I wasn't able to get it to "type" into the script editor field (RATS!~). I think I'll stick with what I wrote :oops:

i also think I like this change to my above script. I set up a 2nd button (in case I didn't want to empty the field first) and put this change in the first line -

Code: Select all

on mouseUp
   put cr & cr after field "Script" of group "Editor" 
Funny enough, it skips exactly 1 line in the script editor, despite the two carriage returns. Now I am thinking about some how triggering the scroll on the script editor field, as it doesn't seem to scroll as the type is going in, so I need to figure out a way to advance it while the script is running. Get messages? I dunno, coffee hasn't hit yet
Image

*Edit - this seems to work for scrolling the field (Thanks to Max's Wiki!)

Code: Select all

on mouseUp
   put cr & cr after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
   
repeat for each character x in the clipboardData
   put x after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
   wait for .5 seconds with messages
   set the vscroll of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" to (the effective textheight of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1") * (the number of lines in field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1")
end repeat

end mouseUp
Now I need to figure out how to insert a tabKey press into that field during the repeat loop through script so that the field auto-colors the script like it would when your typing directly into it :|
Image

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 2:05 pm

Well ok then, I'm stuck :cry:

Code: Select all

on mouseUp
/* this works as intended, if the field is empty, it places the cbData on the first line
 if not empty, it inserts the 2 carriage returns... */
   if field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" is not empty then put cr & cr after field "Script" \ 
         of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
/* this works as intended... */
   repeat for each character x in the clipboardData
      wait for .02 seconds with messages      
      put x after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
/* this works as intended, scrolling the field once text has reached the bottom of the script editor...*/
      set the vscroll of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" \
            to (the effective textheight of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1") \
            * (the number of lines in field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1")
   end repeat
end mouseUp
2 things I tried to implement but haven't figured out yet.
...How to send a tab key press to the field so that after each letter in the cb is placed, the code 'colorizes'. Any other ideas to colorize the code welcome as well.
...How to check if the last character is within a certain distance from the edge of the editor field so that a continuation character can be inserted before continuing. I tried a number of variations of the following, all failed.

Code: Select all

if the formattedWidth of this line of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" > ((the width of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1") - 10) then put " \" & cr after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1"
I'm far more interested in solving the tab/colorizing the script thing than inserting the continuation mark, but as of now I'd take anything someone cares to throw out :mrgreen:
Image

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Script editor typing char by char

Post by MaxV » Tue Aug 28, 2018 4:04 pm

LiveCode_Panos wrote:
Tue Aug 28, 2018 8:05 am
Hi Max,

You might also find the "type" command useful.

Best,
Panos
--
How can use type on the Livecode IDE script editor?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 4:19 pm

MaxV wrote:
Tue Aug 28, 2018 4:04 pm
LiveCode_Panos wrote:
Tue Aug 28, 2018 8:05 am
Hi Max,
You might also find the "type" command useful.
Best,
Panos
How can use type on the Livecode IDE script editor?
I would like to know the answer to that as well, hopefully someone will pop in and spill the beans :D
Image

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Script editor typing char by char

Post by MaxV » Tue Aug 28, 2018 4:34 pm

this seems working:
########CODE to copy and paste with your mouse#######
on MouseUp
repeat for each character x in the clipboardData
put x after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1"
send "reapplyPreferences" to group "Editor" of card "Main" of stack "revNewScriptEditor 1"
wait for .1 seconds
end repeat
end MouseUp

########END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq ########
########Code tested with livecode 9.0.0########
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 5:06 pm

MaxV wrote:
Tue Aug 28, 2018 4:34 pm
send "reapplyPreferences" to group "Editor" of card "Main" of stack "revNewScriptEditor 1"
Oh man, I feel like such a smoo :oops:

That worked perfectly Max!

What I have so far -

Code: Select all

on mouseUp
   if field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" is not empty then put cr after field "Script" \ 
         of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
   
   repeat for each character x in the clipboardData
      wait for .02 seconds with messages      
      put x after field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" 
      
      set the vscroll of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1" \
            to (the effective textheight of field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1") \
            * (the number of lines in field "Script" of group "Editor" of card "Main" of stack "revNewScriptEditor 1")
      
      send "reapplyPreferences" to group "Editor" of card "Main" of stack "revNewScriptEditor 1"
/* need a way to apply the continuation character automatically when we reach the edge of the
 script window... */
   end repeat
end mouseUp

Image

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Tue Aug 28, 2018 8:11 pm

By the way, in case you are wondering why I included the 'vscroll' section and the 'cr' if the field isn't empty, this is what happens without those -
Selection_003.png
No vscroll or cr included...
If you were putting another segment of code after having moved the first lets say, it will run together.

Also, if you don't scroll the field, and you had a longer handler, whatever went past the bottom won't be seen.

*Edit - just in case anyone else might find this useful, I made it a plugin :)
Feel free to improve it (like having it be able to insert continuation characters automagically!)
revClpbrdCopytoSE.rev.zip
I dropped it into the plugins folder, and choose to start it when Lc starts.
(1.37 KiB) Downloaded 5 times
*Edit 2 - tested in Lc vers. 6.5 to 8.1.4 on Linux
Image

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Script editor typing char by char

Post by MaxV » Wed Aug 29, 2018 6:02 am

Great work bogs. I'll use your script for the scroller in my next video.
Here my first video: https://youtu.be/K0fFwHPU7RY
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 2199
Joined: Sat Feb 25, 2017 10:45 pm

Re: Script editor typing char by char

Post by bogs » Wed Aug 29, 2018 12:33 pm

Breakout in 12 minutes? Great job Max (bookmarked the channel). Curious as to the "unpopular'' moniker though, is it a jokey thing?
Image

MaxV
Posts: 1539
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Script editor typing char by char

Post by MaxV » Wed Aug 29, 2018 11:06 pm

bogs wrote:
Wed Aug 29, 2018 12:33 pm
Breakout in 12 minutes? Great job Max (bookmarked the channel). Curious as to the "unpopular'' moniker though, is it a jokey thing?
Try this game https://www.google.co.uk/imghp?q=atari+breakout
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”