This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Plystire's profile picture

[1.4] In-game editor upgrade

Started by Plystire, 25 April 2012 - 02:10 PM
Plystire #1
Posted 25 April 2012 - 04:10 PM
Hello, everyone!

I don't enjoy editing programs outside of minecraft for use on my computers in-game. It's much more involving for me to code while I'm playing. I mean, how else is a creeper going to sneak up on you and blow up your computer while you're coding, right?! Yes, that has happened to me before… not fun, but far more exciting! :)/>/>

Anyway, there are a few things that the in-game editor could use to make coding easier. The following list is just a few things off the top of my head:

- Current line number (sucks when an error is on line 187 and you have to count the lines to find out what line it's talking about)
- Home and End keys to work for navigating to the front/end of a line
- Ctrl+Home/End combination to navigate to the beginning/end of a program
- PgUp/PgDown keys to scroll through program
- "Tab memory" .. basically have the editor remember your indentation when creating a new line, so we don't have to constantly indent every new line to keep things nice and neat (huge pet peave (sp?) of mine is bad code indentation, so this would help me out tremendously!) Please let this work with any kind of leading whitespace including normal spaces as well as tabbed spaces.

I think with just those implemented, coding will be much easier throughout.

Thanks for reading, hope someone out there agrees with me! :)/>/>

~Plystire
Teraminer #2
Posted 25 April 2012 - 05:18 PM
NIce idea and copy pasting text would be good…
Plystire #3
Posted 25 April 2012 - 05:38 PM
NIce idea and copy pasting text would be good…

I thought about putting a copy/paste capability in the list, but figured that would require highlighting to be implemented into the editor as well which, all things considered, made the idea seem less viable considered the added work involved. :)/>/>

While I'm here, another idea (though not as important as my original list of ideas) would be to add in Ctrl+Arrow keys to jump between words on a line. I find myself using this time and again in an IDE, so if it's an easy addition, I'd love to see it happen. :)/>/>

~Plystire
Teraminer #4
Posted 25 April 2012 - 05:57 PM
in minecraft chat you can highlight by pressing Ctrl and left or right key, but you alrady said a function for Ctrl so it could be Alt.
Xfel #5
Posted 25 April 2012 - 08:47 PM
Good idea! i actually wrote a modified version a time a go. It didn't have line numbers, but it also had the missing feature: Support for the del key!

EDIT: Seems I can't attach the file, and the source code is too long to bost it here. Download link: http://dl.dropbox.com/u/63263434/edit2.lua
Plystire #6
Posted 25 April 2012 - 08:53 PM
Oo, support for the Del key would be great, too! Can't believe I forgot to mention that one. Good catch! :)/>/>

~Plystire
Xfel #7
Posted 25 April 2012 - 09:25 PM
OK, I added the line numbers, too. Happy testing. I suggesnt replacing the existing edit program with my derivate: http://dl.dropbox.com/u/63263434/edit
Plystire #8
Posted 25 April 2012 - 10:03 PM
Thanks, Xfel! Definitely already an improvement! Didn't quite envision the line number the way you implemented it. I was thinking more along the lines of how notepad does it, showing "Ln: #" at the bottom. That way we're not shrinking the viewable text, especially if a program becomes very long and hits like quad-digits. :)/>/>

Didn't even put 2 and 2 together to realize the edit command was a program in and of itself, lol! I might toy around with the one you wrote to have the line numbers how I like it.

Much appreciate the effort, though! Thanks again! :)/>/>

~Plystire
LordDrako #9
Posted 26 May 2012 - 06:17 PM
Well syntax highlighting would be pretty cool :-)
Xfel #10
Posted 27 May 2012 - 07:28 AM
Well without colors that will never work.
LordDrako #11
Posted 27 May 2012 - 10:29 AM
I think it shouldn't be too hard to implement something like term.setForeground and term.setBackground (or evtl. term.setColors) to change the internal color attributes of the term class for example. getColors would be useful as well to be able to restore the old settings later.
term.write, print and so on would then just use the stored color values for showing text. (Text already printed won't be affected).
That is the way that SetConsoleTextAttributes (Win32-API) works :-)
Xfel #12
Posted 27 May 2012 - 10:34 AM
You know, I totally agree with you. But for some reason, dan doesn't want to add it. The reason mentioned is network traffic, and I see the possible problem, but then, CC sends the network strings in UTF8-format, which means that half of all characters that could be expressed in one byte are send in two. this second byte could also be used to transmit two 4-bit color values (which would be enough for the sixteen default minecraft colors). Well, it's not my mod, so dan can implement it as he pleases.
Pokechu22 #13
Posted 03 July 2012 - 10:50 PM
You can Currently paste, but the problem is that you need to press control to open the menu, then release it and then do Control-V. Otherwise it will exit or save your program.
Mendax #14
Posted 04 July 2012 - 03:36 AM
Why not add Copy/Paste to the CTRL menu? That'd work I guess
Xfel #15
Posted 04 July 2012 - 09:13 AM
the paste function is part of the cc hardware, you can't access it from your program.

However, a function like os.getClipboard()/os.setClipboard(string) would be very useful…
Pinkishu #16
Posted 04 July 2012 - 03:23 PM
the paste function is part of the cc hardware, you can't access it from your program.

However, a function like os.getClipboard()/os.setClipboard(string) would be very useful…

Make one :P/>/>

rawset(os, "getClpboard", function() return os.clipboard end)
rawset(os, "setClipboard", function(val) rawset(os,"clipboard",val) end)
Xfel #17
Posted 04 July 2012 - 03:56 PM
I meant the system clipboard. However I realized that that would not work on servers…

And I would not encourage the use of rawset, by the way.
Pinkishu #18
Posted 04 July 2012 - 08:40 PM
Well for _G its either rawset or table.insert cause CC blocks normal editing there for some reason :3
ChunLing #19
Posted 07 July 2012 - 05:00 AM
Wouldn't you normally write your programs in a safe location and then distribute them to your other computers/turtles in mines and forests using floppies?
Tiin57 #20
Posted 16 July 2012 - 02:32 PM
Quite honestly, this would be amazing. I have to use SciTe and save the output files directly into my lua/programs folder to do anything decent. It's quite annoying and would be great if this were implemented. I know this isn't the MC forums, but I give you diamonds for such a clean presentation of a good idea instead of being like some people (i.e. WE NEEDS BETTA TXT EDITAR PL0X).
/
/
/
/
That's supposed to be a diamond, by the way. :P/>/>
kazagistar #21
Posted 16 July 2012 - 02:40 PM
I will play devils advocate. First of all, writing code inside of CC is going to be inferior to writing it outside of CC in every case, so fancying up the editor is meaningless; if you want to seriously write code, you are going to do it outside of CC, and then transfer it in (via a number of methods of doing so).

Second of all, there are many cases in which you might not want some of the features. This means there would have to be some way to disable them, via a settings file of some kind. As it is, there is no standard way to do settings, and making a default application that has a settings file would break the elegant simplicity of CC.

In the server I play on, we have a modified text editor that has a number of additional features and shortcuts, including faster text navigation and saving indentation levels. However, a program I use to copy things into CC via paste was broken by the indentation settings, so I had to make a copy of the native edit program and use that one instead.

If you really do want to add a lot of features, I would just recommend making a new editor that has them, instead of messing with the existing one.
Emerae #22
Posted 20 July 2012 - 07:20 AM
OK, I added the line numbers, too. Happy testing. I suggesnt replacing the existing edit program with my derivate: http://dl.dropbox.com/u/63263434/edit

Using the goto function,
Your code was not checking if an empty string was entered
Or for an integer, Of any sort.
Entering any of the above would crash trying to perform equations on "nil", And "int" values.
Causing a loss of all unsaved work…. (goto to line 0 and typing does this as well, Also fixed lulz)

I learnt lua yesterday and with a simple loop to stop escapes of values
And some actual checking of variables….

I fixed it lulz!

http://pastebin.com/rzzUXgd0

Is it so hard to check for a fucking string greater than 0