Works with one thing but not the other?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Works with one thing but not the other?

Post by MadByte »

Why not simply reset the angle to 0 when it get's bigger then 360 ?
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Works with one thing but not the other?

Post by NightKawata »

Jasoco wrote:Also, don't require from within the love.load function. Require from the top of the main.lua and don't require main. It's already being run.
Besides requiring main, there really isn't too many faults for requiring files from within love's load function. iirc Mari0 also does the same thing, and it works fine. (Doesn't mean it's good per se, but I don't see the huge issue for doing that. Meh.)
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Works with one thing but not the other?

Post by slime »

In fact, requiring from inside love.load means code in the required files will use the same proper randomseed that gets applied just before love.load. It also means any print statements in those files will properly output to the console in windows (in 0.9.0 this is fixed so that print will work before love.load.)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Works with one thing but not the other?

Post by Robin »

slime wrote:In fact, requiring from inside love.load means code in the required files will use the same proper randomseed that gets applied just before love.load. It also means any print statements in those files will properly output to the console in windows (in 0.9.0 this is fixed so that print will work before love.load.)
There's the answer why requiring inside of love.load() is a bad idea. Alright, it's not so much a "Wrong" as something that hides badly designed code (as in the above, for instance). It is my opinion that you need to have a very good reason to have anything at the top level of your modules other than assignment statements (function declarations fall under assignment).
Help us help you: attach a .love.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Works with one thing but not the other?

Post by slime »

Robin wrote:
slime wrote:In fact, requiring from inside love.load means code in the required files will use the same proper randomseed that gets applied just before love.load. It also means any print statements in those files will properly output to the console in windows (in 0.9.0 this is fixed so that print will work before love.load.)
There's the answer why requiring inside of love.load() is a bad idea. Alright, it's not so much a "Wrong" as something that hides badly designed code (as in the above, for instance). It is my opinion that you need to have a very good reason to have anything at the top level of your modules other than assignment statements (function declarations fall under assignment).
So you basically want to defer code from the top level into a function, just for the sake of having it in a function? Not all code is designed to be executed multiple times during the program's lifetime, not to mention both the issues I mentioned above will cause some serious headaches if you don't already know about them.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Works with one thing but not the other?

Post by T-Bone »

Robin wrote:
slime wrote:In fact, requiring from inside love.load means code in the required files will use the same proper randomseed that gets applied just before love.load. It also means any print statements in those files will properly output to the console in windows (in 0.9.0 this is fixed so that print will work before love.load.)
There's the answer why requiring inside of love.load() is a bad idea. Alright, it's not so much a "Wrong" as something that hides badly designed code (as in the above, for instance). It is my opinion that you need to have a very good reason to have anything at the top level of your modules other than assignment statements (function declarations fall under assignment).
I'm not sure I understand you correctly... Isn't requiring modules outside of functions putting things at the top level of modules, which you say should be avoided?

I've always thought that putting as much as possible inside functions is good practice. Requiring things from within functions (like love.load) seems to me like the correct way of following that practice.
RunningGamesStudios
Prole
Posts: 46
Joined: Fri May 31, 2013 9:42 pm

Re: Works with one thing but not the other?

Post by RunningGamesStudios »

MadByte wrote:Why not simply reset the angle to 0 when it get's bigger then 360 ?

But if it changes the angle by let's say 4 once it goes over 360 insted of setting back to 4 it will go to 0
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Works with one thing but not the other?

Post by Robin »

That's what % is for.

Code: Select all

180 % 360 == 180
359 % 360 == 359
360 % 360 == 0
364 % 360 == 4
T-Bone wrote:I'm not sure I understand you correctly... Isn't requiring modules outside of functions putting things at the top level of modules, which you say should be avoided?
Well, of course calls to require as well (and a single return statement at the end, returning the module dictionary). But that's basically it.

This structure means that all dependencies are in place before you do anything that could need those dependencies. It makes things simpler by not having to see calls to require as flow control and "active code" that crosses file/module boundaries. Instead you can see them as passive declarations of dependencies, similar to Java (or, as a closer comparison, idiomatic C/C++, Go or Python).

Again, I shouldn't have called what RunningGamesStudios did with using require in love.load() "wrong" (even though it fit so nicely in the numbered list). I would still advice against it, though.
Help us help you: attach a .love.
RunningGamesStudios
Prole
Posts: 46
Joined: Fri May 31, 2013 9:42 pm

Re: Works with one thing but not the other?

Post by RunningGamesStudios »

Robin wrote:That's what % is for.

Code: Select all

180 % 360 == 180
359 % 360 == 359
360 % 360 == 0
364 % 360 == 4
T-Bone wrote:I'm not sure I understand you correctly... Isn't requiring modules outside of functions putting things at the top level of modules, which you say should be avoided?
Well, of course calls to require as well (and a single return statement at the end, returning the module dictionary). But that's basically it.

This structure means that all dependencies are in place before you do anything that could need those dependencies. It makes things simpler by not having to see calls to require as flow control and "active code" that crosses file/module boundaries. Instead you can see them as passive declarations of dependencies, similar to Java (or, as a closer comparison, idiomatic C/C++, Go or Python).

Again, I shouldn't have called what RunningGamesStudios did with using require in love.load() "wrong" (even though it fit so nicely in the numbered list). I would still advice against it, though.


I don't get how I would use that to correct the angle though
User avatar
jasonisop
Citizen
Posts: 93
Joined: Thu Jun 21, 2012 1:35 am

Re: Works with one thing but not the other?

Post by jasonisop »

RunningGamesStudios wrote:I don't get how I would use that to correct the angle though
Is there a face palm smiley?
Post Reply

Who is online

Users browsing this forum: Bing [Bot], dusoft, Google [Bot] and 6 guests