LOAD... / GEN... (or any creation command) change

Previous topic - Next topic

FutureCow

I just thought of an idea that might solve a lot of the bugs people have.

What do you think about making all the load commands (LOADANIM, X_LOADOBJ, X_OBJSTART, GRABSPRITE, LOADFONT etc) not work with ID = 0 ?

My justification :-
As a variable's value defaults to 0 on creation, when you forget to assign a value to your variable (or you have a bug somewhere in your code, or even just a typo in the name of the variable) your code will end up creating/loading over the top of object 0. You then have to work out why an object you haven't touched now has a funny texture or wrong image, or an unrelated sound has changed. If object 0 doesn't get seen much (or heard much if it's a sound) it can be a while before the bug shows itself and it can be a pain to track down. If the load/creation commands only worked for locations 1+ then I think you could stop a lot of bugs before they even happen.

With this, you'd need the GEN... commands to start at 1+ too. Actually, just changing the GEN commands at 1 without the other changes would probably solve a lot of issues (though I think changing all the commands would be better).

I realise this would break existing code, but I think the benefits (from this point forward) would outweigh the issues. What do you all think?

Moru

I think you should activate Explicit declarations in Project Options, this will fix most of those issues :-) Oh, and always test your code with debug mode on first.

I don't like when existing code suddenly stops working. You could write your own versions of the commands and tell the user when there is something strange going on. You could even check if there is a texture loaded before overwriting it and warn for that.

FutureCow

I don't like breaking existing code either, but I think the benefit outweighs the problems.

Yes, you could write your own versions of some if not all the commands, but I'm thinking more for beginner users who are more likely to run into these problems. And I don't particularly want additional libraries I have to load into my projects for more "safe" loading and creation of resources. Harden the commands and you don't need to write duplicate code to do basically the same thing the language already does.

Moru

But you don't need to do any of those things to cover the problem. Just set the Explicit declarations in the options and the compiler will fail on forgotten/misstyped variables. Since all my code depends on counting starting on 0 I don't particularly like remaking my code to fix someone elses code :-)

FutureCow

But do you want to force explicit declarations on beginners? That's mainly who I was thinking of who'd benefit from it.

Moru

All beginners I have helped so far would have been much better off with Explicit declarations on because they had missunderstood scope or just forgotten to declare variables so yes I want to force it on them. Call me cruel but I think it will help them, not make it harder. :-)

FutureCow

Maybe it should be explicit on by default instead then? (though I still think mine would be a better long term solution  :P )