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

I need help with my program

Started by cpblack, 30 August 2015 - 11:28 AM
cpblack #1
Posted 30 August 2015 - 01:28 PM
I was making a game and I ran into a few problems. First problem being there is too much lag when generating the images. Secondly the looting mechanic isnt working, neither is the display inventory. Any useful help is appreciated
http://pastebin.com/Cjwd8W3J
Edit: Also I need help making it so that the character doesn't clone itself when it first moves
Edited on 30 August 2015 - 11:29 AM
Bomb Bloke #2
Posted 31 August 2015 - 01:34 AM
You could do a few things to make it more readable, for starters. You've somehow managed to avoid performing any indentation at all; having done so would've helped you spot things like the missing "end" between lines 253 and 254.

And please use the keys API - numbers like 57 aren't meant for people to read. Terms like keys.space are.

Frame rate could be improved in a few ways, mostly centering around the idea of not clearing the screen if you don't have to. If an entity hasn't moved, then simply leave it on the screen where it was. If an entity HAS moved, draw it in its new location, then redraw whatever remains at the old one (or your "floor" if there's nothing there).

If you feel you must clear everything, do it a line at a time (clear line, draw line, clear line, draw line…), to reduce the time each area of the screen stays "blank".

Your deleteByNumber() function duplicates either entities[r + 1] or entities[r + 3]. It looks like you want to replace the whole contents of that function with a single table.remove() call instead - this automatically shuffles all the other elements down to fill the gap.
Edited on 30 August 2015 - 11:35 PM
H4X0RZ #3
Posted 31 August 2015 - 02:12 PM
Also on line 24 is something wrong. "~= 'girl'" shouldn't be in the brackets I believe. (but this isn't really necessary if you replace it with what Bomb Bloke told you)