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

CCJam why texty failed.

Started by supernicejohn, 30 July 2016 - 12:23 PM
supernicejohn #1
Posted 30 July 2016 - 02:23 PM
First off, I'd like to thank the judges for the kind words. It was very nice to be reading positive feedback on a program that was deeply flawed.
The things that were wrong with the program:
1. Save format. The judges didn't mention this, but I believe that if something written in texty would be opened in any other text editor (CC or other) you will just see a serialized table. Texty saves by getting every character in an x,y position, reformatting that to xxxyyy, then saving that as one character.
Example, "hi" would be stored as:
{
[ "001001" ] = "h"
[ "002001" ] = "i"
}
Very efficient =P, didn't make an export function of any sort…
2. Speed. When I was testing the program I was using "drawAll()" for every character. replacing that with "drawPart(xcurrent-1,ycurrent,xcurrent,ycurrent)" makes the program approximately 500x faster (kinda). That's what I get for not checking over my program. Still managed to get one 3 in speed…
3. The biggest flaw… getLine() which, since I didn't know the difference between "not text[a(x,y)] == nil" and "text[a(x,y)] ~= nil" (and still kinda don't), always returned 1. That led to everytime you pressed backspace when it should go to the last character of the above line, it instead put itself at x=1.

I have fixed nr 2. and nr 3. and it's actually functional now and can be viewed at https://github.com/S...ohn/TextyReboot but it's nothing I ask of you.

All in all it was fun to be in a competition and fun to get feedback, and I learned things! Which summed up, I think is what CCJam strived to be. :)/>

PS: 1lann and apemanzinna mentioned that the arrow keys didn't really work well. I haven't started to implement them yet… thanks for the idea! Knew something was missing! :P/>
HDeffo #2
Posted 30 July 2016 - 04:01 PM
Since you said you still don't understand 3 very well I will attempt to explain this. Essentially you have to read your statement from left to right

writing not text[a(x,y)] == nil is the same as writing ( not text[a(x,y)] ) == nil. This will either end up being true == nil or false == nil and both of those statements in the end return false. Alternatively you don't even need the nill part in there at all just put
 if text[a(x,y)] then 
Lua evaluates anything that isn't nil or false as true and evaluates nil as false
Edited on 30 July 2016 - 02:02 PM
supernicejohn #3
Posted 30 July 2016 - 06:19 PM
Since you said you still don't understand 3 very well I will attempt to explain this. Essentially you have to read your statement from left to right

writing not text[a(x,y)] == nil is the same as writing ( not text[a(x,y)] ) == nil. This will either end up being true == nil or false == nil and both of those statements in the end return false. Alternatively you don't even need the nill part in there at all just put
 if text[a(x,y)] then 
Lua evaluates anything that isn't nil or false as true and evaluates nil as false
Ohhh I get it then!
I think. So would "if not (text[a(x,y)] == nil) then" also be what I'm looking for?
SquidDev #4
Posted 30 July 2016 - 06:30 PM
I think. So would "if not (text[a(x,y)] == nil) then" also be what I'm looking for?

Yeah. not (x == y) is the same as (x ~= y).
Edited on 30 July 2016 - 04:30 PM