Page 2 of 5
Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 8:22 pm
by Robin
Tesselode wrote:the link will break in a day or two.
No it won't. The only broken links are from before the Attack of the Aliens, which started out as the web site being split and later being down completely, after which most posts were recovered, but attachments were not.
Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 8:39 pm
by Xkeeper
I hope you don't mind if I play a bit with it -- it will be kind of fun to see what else I can do (and maybe help you out, who knows).
I'll also see if I can figure out what went wrong.

Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 8:40 pm
by Robin
That code... hurts.
The real problem lies in the loop which starts on line 15 (“for line in file:lines() do ...”). You see, objectnum is always incremented (I'd rather you'd do away with it completely), even if the object_type is not "platform". Hilarity does not ensue.
Especially since (rolling drums) object_type is NEVER "platform". Because it's a table.
Code: Select all
object_type[objectnum]=string.sub(currentline,1,string.find(currentline,",")-1)
if object_type=="platform" then
Replace that if with
Code: Select all
if object_type[objectnum] == "platform" then
helps.
Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 8:44 pm
by giniu
Robin wrote:Especially since (rolling drums) object_type is NEVER "platform". Because it's a table.
hehe, look at last post on previous page

But anyway, it confirms it - but anyway fixing it leads to next problem we will leave you chance to deal with

Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 9:04 pm
by Robin
giniu wrote:hehe, look at last post on previous page

Oh, sorry, I didn't see that.

Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 11:33 pm
by Tesselode
Thanks guys. Anyway, errors ahoy. It would be great if you could fix this new error, and if you find any other ones, feel free to fix them too if it doesn't hurt you too much.
Seriously, what does indexing a field mean?
P.S. - The code is now commented for both my sake and everyone else's sake. Hopefully this will make it easier to tell what's supposed to be going on.
(It should also make it easier for XKeeper to play around with it.)
Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 11:48 pm
by kikito
Tesselode wrote:
Seriously, what does indexing a field mean?
It means doing
field.something or
field[something_else].
EDIT: also
field:something_completely_different()
Re: Tilt - physics puzzler
Posted: Wed Aug 04, 2010 11:55 pm
by Xkeeper
Looking through this, I'm going to try to work on it a bit and do some stuff.
My thoughts so far, though:
Code: Select all
object_x={}
object_y={}
object_type={}
You're using arrays backwards. It would be wiser to do this:
Code: Select all
objects[1]['x'] = (object x)
objects[1]['y'] = (object y)
objects[1]['type'] = (etc)
objects[2]['type'] = ....
This way, you can create a new object easily by manipulating only one array, and to destroy it is easily similar (objects[id] = nil).
I'm going to clean it up a bit for you, hopefully simplifying the LoadLevel routine too for you. Stay tuned

Re: Tilt - physics puzzler
Posted: Thu Aug 05, 2010 12:05 am
by Robin
Something that's better to avoid is using global variables as loop counters.
Xkeeper wrote:You're using arrays backwards. It would be wiser to do this:
Code: Select all
objects[1]['x'] = (object x)
objects[1]['y'] = (object y)
objects[1]['type'] = (etc)
objects[2]['type'] = ....
Almost. It's easier to type
objects[1].x than
objects[1]['x'], while they mean exactly the same thing.
Re: Tilt - physics puzzler
Posted: Thu Aug 05, 2010 12:20 am
by Xkeeper
Robin wrote:Something that's better to avoid is using global variables as loop counters.
I agree. Though I'm curious, and this has always bugged me about Lua; if you manage your global variables carefully (to only things that really need to be global), is there a downside to omitting
local within functions/loops? Especially for temporary values that are set and only used after that point.
Almost. It's easier to type objects[1].x than objects[1]['x'], while they mean exactly the same thing.
D'oh, true. I come from PHP-land so ... yeah.