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

Binary Editor In Minecraft

Started by bentallea, 31 August 2013 - 09:32 PM
bentallea #1
Posted 31 August 2013 - 11:32 PM
Hello everyone, this is the second version of my first program released on this forum. It is a simple binary editor designed to run inside computercraft. I would like some help debugging, as there maybe a couple of bugs

pastebin get FCdZNBDA hex
to run this program run hex <path> [display]
arguements:
  • path to file, required, can handle absolute or relative locations, but not directories.
  • where to display the file. if you want to use the terminal window even when a monitor is attached to the computer, make this parameter either "term" or "terminal". to use a specific monitor, this parameter should be the direction the monitor is on.
This program supports both color and regular computers and monitors.
if there is no parameter for a monitor then the terminal window will be used unless a monitor is present. the current order for checking the monitors is top, bottom, right, left, front, back in that order, and the monitor used is the last one found.

Also added is an on screen keyboard specially made for this program. no one suggested it, but i thought it would come in handy for usability on an external monitor, since i know there is no keyboard access when using a monitor unless you open the cc interface. This should prevent that nuisance.

Also, now the code is on pastebin for easier installation.
bjornir90 #2
Posted 11 September 2013 - 03:41 PM
This seems to have been done in a good way :)/> especially for your first program ;)/> but could you please add a link from pastebin, it help us installing your program.
immibis #3
Posted 12 September 2013 - 06:43 AM
I would like some help debugging, as there are a couple of bugs that i noticed: using an advanced computer/turtle, the color mode defaults to true despite being set to false

if term.isColor() then
menuItems[#menuItems + 1] = "Toggle Color"
colr = true
end
That's why.
BigTwisty #4
Posted 12 September 2013 - 12:59 PM
There are many things that could be done to simplify this.
  1. Use event "char" instead of "key" and just compare it against the string "0123456789abcdef". This gets rid of about 14 lines of redundant code.
  2. Store your data in a table containing 32 character strings of hex. This would make it really easy to scroll and simplify updates from the "char" event. Keep all data in string form until ready to write back to the file. Strings are all we want to see; there's no reason to keep switching back and forth until you have to.
  3. Use tostring() and tonumber() to convert between hex and decimal. This gets rid of the last 32 lines of your main loop.
  4. "mouse_click" should validate that the user is clicking on a portion of the screen containing data before moving the cursor there.
Additional features:
  1. "mouse_scroll" event.
  2. monitor support.
  3. ?
  4. profit!
Lyqyd #5
Posted 12 September 2013 - 02:15 PM
Moved to Ask a Pro.
bentallea #6
Posted 25 September 2013 - 11:42 PM
Thanks for the recommendations BigTwisty. I will try implementing your ideas.

There are many things that could be done to simplify this.
  1. Use event "char" instead of "key" and just compare it against the string "0123456789abcdef". This gets rid of about 14 lines of redundant code.
  2. Store your data in a table containing 32 character strings of hex. This would make it really easy to scroll and simplify updates from the "char" event. Keep all data in string form until ready to write back to the file. Strings are all we want to see; there's no reason to keep switching back and forth until you have to.
  3. Use tostring() and tonumber() to convert between hex and decimal. This gets rid of the last 32 lines of your main loop.
  4. "mouse_click" should validate that the user is clicking on a portion of the screen containing data before moving the cursor there.
Additional features:
  1. "mouse_scroll" event.
  2. monitor support.
  3. ?
  4. profit!
After doing research, tonumber works with numbers with base other than ten, but tostring does not. so i still need a function to convert the numbers to a string representing the number in base 16.
niofalpha #7
Posted 26 September 2013 - 08:17 PM
Looks amazing! I have no use for binary but still, very good!
Wojbie #8
Posted 27 September 2013 - 04:41 AM
For converting from base 10 to any base you can use http://stackoverflow...-base-converter
Thats what i am using anyways.
BigTwisty #9
Posted 28 September 2013 - 02:13 AM
For converting from base 10 to any base you can use http://stackoverflow...-base-converter
Thats what i am using anyways.

Try:

string.format("X", number)
bentallea #10
Posted 07 October 2013 - 12:01 AM
i updated the code, please see first post.