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

frame A graphics thing (Am I doing it right?)

Started by supernicejohn, 20 November 2015 - 10:49 AM
supernicejohn #1
Posted 20 November 2015 - 11:49 AM
So! I tried to make some games, (unique) but I decided to start small, with a paint program similar to the one from nitrogenfingers. Then I realized that only writing things to the screen wont make them stay if something else is overwriting them… Genius. I made a try to fix that. first I did a simple one that worked (100 lines no color support) And this here is that; http://pastebin.com/mtdfr836

After trying it out on a simple game (not worth mentioning) It seemed a little restricting without colors though.

So I made a new one, and after 1 hour of bugtesting, it kinda works! Here it is if you want to try it; http://pastebin.com/hVyVanQk
It's still buggy but the concept is the same as in the first version which is 99% bug free =)

If you don't want to look in the code what it means, =P, then: What it does is create a table "t" in which it stores all pixels on the screen in the format xxxyyy (or xxyy old format), and then stores a single character string at that key. The v2 also has two tables like this one, for color and for background color.

What I want to know!: Am I doing it right?
For more details, ask or look at the code =)
Thanks!
Konlab #2
Posted 21 November 2015 - 10:19 AM
Your program/utility is really interesting but by looking at the code I can tell that your code is not modular and you use global variables. What I mean by this is that re-using your code is impossible without modifying it.
I also don't really get why are you using strings for keys, it is an interesting thing and not sure if it is better to use multidimensional tables instead of strings and I don't know which results in better performance.
Edit: your program is meant to be loaded as API?
Edited on 21 November 2015 - 09:21 AM
supernicejohn #3
Posted 21 November 2015 - 06:31 PM
Yup, I use it as an API,(example: framev2.colour.putBkgRaw(…)) I'm planning to do some simple stuff with it and this seemed to me like a good place to start.
As for the feedback, thanks! Just a question, did you look at the new one instead of the old one? Because since this is a learning experience I looked at the v1 and thought of what I could improve. =P
The only globals in the v2 are the tables? (which is not intended, and I'm not good enough to know what it would affect to make them local)
The strings for keys is something else I forgot… Oh well =D

I also don't really get why are you using strings for keys, it is an interesting thing and not sure if it is better to use multidimensional tables instead of strings and I don't know which results in better performance.

That I'm using t[a] (t[xxxyyy]) = character instead of t[x][y] = character? Well it seemed like the latter was the popular one so I thought "why not make it different?" and it seems to work fine for me, but indeed not sure if it makes a difference. So in the end… well it does something =)

What I mean by this is that re-using your code is impossible without modifying it.

I don't understand, I know that the v2 is a buggy mess that doesn't work but v1 does I'm fairly sure (it did for my game).

Thanks for the critique ;)/>
Konlab #4
Posted 21 November 2015 - 07:27 PM
Yup, I use it as an API,(example: framev2.colour.putBkgRaw(…)) I'm planning to do some simple stuff with it and this seemed to me like a good place to start.
As for the feedback, thanks! Just a question, did you look at the new one instead of the old one? Because since this is a learning experience I looked at the v1 and thought of what I could improve. =P
The only globals in the v2 are the tables? (which is not intended, and I'm not good enough to know what it would affect to make them local)
The strings for keys is something else I forgot… Oh well =D

I also don't really get why are you using strings for keys, it is an interesting thing and not sure if it is better to use multidimensional tables instead of strings and I don't know which results in better performance.

That I'm using t[a] (t[xxxyyy]) = character instead of t[x][y] = character? Well it seemed like the latter was the popular one so I thought "why not make it different?" and it seems to work fine for me, but indeed not sure if it makes a difference. So in the end… well it does something =)

What I mean by this is that re-using your code is impossible without modifying it.

I don't understand, I know that the v2 is a buggy mess that doesn't work but v1 does I'm fairly sure (it did for my game).

Thanks for the critique ;)/>/>
I looked at the second link with colors
1. Then it's ok.
2. It is good to try new things and I'm not sure which is the faster
3. I meant by that if you wanted to copy some functions from code to other project you have to change var names, etc. Imagine the term api used global vars. It would be very hard to tell what is the function actually doing. (Imagine what if term.setcursorpos got its coords from a global var) Using global vars at all is a mistake unless you really have to. Locals are faster and safer.
And please don't take this like I'm critizing you. Your program is cool I just found some places which could be improved.
supernicejohn #5
Posted 21 November 2015 - 09:06 PM
Working on v3, which will be developed at home, in difference to v1 and v2 which were made in Prague and in math class (heh) respectively.
v3 will use term.blit() mostly… :P/>