[Just for fun] Roast my code.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: [Just for fun] Roast my code.

Post by Bobble68 »

pgimeno wrote: Sun Dec 31, 2023 12:14 pm Also, namespace pollution is a thing, and one may inadvertently use the same name for two different things, and have one overwrite the other, causing a bug.
I did this myself at one point - for some unknown reason, I have one module that uses a local variable named, and a global for the rest of the program also called mouse. For a while it wasn't an issue, but when I eventually wanted to make use of the functionality of the global version, I found that I was stuck without fixing the whole module :death:. The way I got around it is by making another local variable at the start called gmouse, that was just a reference to the global version - not the most elegant solution, but it works. I now know not to do that.
Dragon
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Just for fun] Roast my code.

Post by pgimeno »

Bobble68 wrote: Sun Dec 31, 2023 1:06 pm I did this myself at one point - for some unknown reason, I have one module that uses a local variable named, and a global for the rest of the program also called mouse. For a while it wasn't an issue, but when I eventually wanted to make use of the functionality of the global version, I found that I was stuck without fixing the whole module :death:. The way I got around it is by making another local variable at the start called gmouse, that was just a reference to the global version - not the most elegant solution, but it works. I now know not to do that.
Remember that you can also use _G.mouse. Some style guides even mandate all globals to be referenced through _G.
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: [Just for fun] Roast my code.

Post by Bobble68 »

pgimeno wrote: Mon Jan 01, 2024 3:13 pm Remember that you can also use _G.mouse. Some style guides even mandate all globals to be referenced through _G.
Had not occured to me that this was possible, but I suppose it would be (at the time I did the fix I didn't know about _G).
Dragon
User avatar
zalander
Citizen
Posts: 72
Joined: Mon Jan 09, 2023 5:58 am
Location: India

Re: [Just for fun] Roast my code.

Post by zalander »

milon wrote: Thu Dec 28, 2023 4:14 pm Why is 'tmp' a global??? Local variables have far better performance!

Also, try to structure your game to not need love.load() at all - it'll help you improve your code structure.
This code was for a challenge "Create the worst text editor"(Given by a friend). Sooo the performance has to be.
Image
Using LOVE to make everything except games :crazy:

Code: Select all

astring = "pog"
print(astring)
--pog
User avatar
zalander
Citizen
Posts: 72
Joined: Mon Jan 09, 2023 5:58 am
Location: India

Re: [Just for fun] Roast my code.

Post by zalander »

Bobble68 wrote: Fri Dec 29, 2023 12:22 pm mr global.png
Azzla wrote: Sun Dec 24, 2023 7:07 am You have no window wrapping so you can type on a line forever, but that's more of a "incompleteness" thing than a code thing.
Also, love.graphics.printf has text wrapping built in, you might want to consider using it instead.
Printf kinda breaks the line number system. Soo ill need to fix that before i add printf.
Using LOVE to make everything except games :crazy:

Code: Select all

astring = "pog"
print(astring)
--pog
Post Reply

Who is online

Users browsing this forum: No registered users and 69 guests