Page 1 of 2
Script editor typing char by char
Posted: Tue Aug 28, 2018 12:25 am
by MaxV
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

)
Any ideas to do it?
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 1:39 am
by bogs
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
*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!!!

Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 8:05 am
by LiveCode_Panos
Hi Max,
You might also find the "type" command useful.
Best,
Panos
--
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 10:25 am
by bogs
Hmm. A new toy to play with! Thank you Panos
@Max, I expect to see a link in this thread to these amazing videos my friend

Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 10:59 am
by richmond62
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 (7.47 KiB) Viewed 10258 times
-
typingRat
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 11:05 am
by bogs
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
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
*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

Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 2:05 pm
by bogs
Well ok then, I'm stuck
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

Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 4:04 pm
by MaxV
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?
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 4:19 pm
by bogs
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

Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 4:34 pm
by MaxV
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########
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 5:06 pm
by bogs
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
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
Re: Script editor typing char by char
Posted: Tue Aug 28, 2018 8:11 pm
by bogs
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 -

- 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 256 times
*Edit 2 - tested in Lc vers. 6.5 to 8.1.4 on Linux
Re: Script editor typing char by char
Posted: Wed Aug 29, 2018 6:02 am
by MaxV
Great work bogs. I'll use your script for the scroller in my next video.
Here my first video:
https://youtu.be/K0fFwHPU7RY
Re: Script editor typing char by char
Posted: Wed Aug 29, 2018 12:33 pm
by bogs
Breakout in 12 minutes? Great job Max (bookmarked the channel). Curious as to the "unpopular'' moniker though, is it a jokey thing?
Re: Script editor typing char by char
Posted: Wed Aug 29, 2018 11:06 pm
by MaxV
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