r/badcode • • Dec 05 '20

other language Gamedevs, take notes

Post image
6.5k Upvotes

104 comments sorted by

662

u/Nipatiitti Dec 05 '20

Cursed formatting

215

u/DefinitionOfTorin Dec 05 '20

And no parentheses round the condition but curley ones for content? Is this Swift or something lol?

76

u/jimmpony Dec 05 '20

maybe rust

42

u/stp412 Dec 05 '20

Maybe even lua perhaps

Edit:nvm there’s an !

25

u/PulleQ Dec 06 '20

...and {} instead of then end

7

u/rotenKleber Dec 16 '20

It's gotta be GML, the scripting language for gamemaker

→ More replies (2)

11

u/fried-noodles_ Dec 05 '20

Go?

16

u/jgeez Dec 06 '20

Can't be Go, Go enforces open curly on the same line as the if statement

22

u/[deleted] Dec 06 '20

What kind of language enforces style?

→ More replies (8)
→ More replies (3)

4

u/notqthrowaway Dec 06 '20

I think that's a no go.

5

u/[deleted] Dec 06 '20

Looks like Game Maker Language where semicolons and parentheses are optional

3

u/Woolly87 Dec 06 '20

The compiler would say that it’s valid Swift, but no true Scotsman sane Swift programmer would format it like that.

6

u/edo-lag Dec 05 '20

Imho it's more readable and aesthetically better, but that's my opinion... Rust is my main programming lang so maybe that's why

42

u/Leeeo69 Dec 05 '20

I hereby declare your subjective opinion as incorrect.

→ More replies (7)

5

u/quantumgoose Dec 06 '20

Tbh I'm so used to using parentheses from C that I still use them in Rust , but I always end up removing them to get rid of the Clippy warnings

→ More replies (2)

8

u/[deleted] Dec 06 '20

298

u/botle Dec 05 '20

Yup, that's bad code. It can obviously be simplified to

fps = 60

49

u/the_monkey_of_lies Dec 06 '20

You're hired, when can you start?

66

u/dlawodnjs Dec 06 '20

what if fps was higher than 60? ...oh wait.

edit: I obviously cannot read code

18

u/TVflea Dec 30 '20

And what if fps is already 60? You would then set fps to 60 redundantly, which would be an O(log(n)) operation, since the CPU needs to flip log(n) bits. Quite wasteful and unoptimized

20

u/cstmth Dec 06 '20

Wrong.

while (true) { fps = 60 }

33

u/botle Dec 06 '20

Sure, why not. People got plenty of cores to spare these days.

4

u/[deleted] Mar 13 '21

BRILLIANT!!

235

u/A_Sad_Shoe Dec 05 '20

damn, why didn't yandere dev think about this when implementing his fps counter

93

u/ITSOPBTW Dec 05 '20

I wonder how performance friendly would be a Python based game engine.

72

u/GandelXIV Dec 05 '20

The fastest i know is pygame and it is pretty slow

44

u/oxetyl Dec 05 '20

I do a lot of stuff in pygame because it's so easy, but yeah, if performance is your main concern, it would not be a good choice

7

u/[deleted] Dec 06 '20

I personally use raylib if i need to use python and that works quite fast.

13

u/icuninghame Dec 06 '20

Civilization IV was built using Python, I think.

17

u/GandelXIV Dec 06 '20

Civ IV used Python for the mechanics but the rendering was made in cpp i think.

9

u/botle Dec 05 '20

Well, it can be made to run at 60 fps no matter what.

13

u/[deleted] Dec 05 '20

That exists and it does not do as well as other low level language's engines obv

2

u/[deleted] Mar 29 '21

hi I'm late but Godot uses gdscript which iirc is a superset of python

69

u/[deleted] Dec 05 '20

obviously should have been written in HTML to be better at fast.

21

u/[deleted] Dec 05 '20

HTML and JS games run really fuckin fast. For web browser games. Which needs a slow AF web browser

15

u/IDatedSuccubi Dec 05 '20

I mean, WebGL doesn't care what language issues commands, it's not the JS interpreter that draws everything

→ More replies (2)

24

u/nikstick22 Dec 06 '20

This is the sort of thing AI would do if its instructions were to improve fps but it measured fps by reading the fps counter on the screen.

This reminded me of the videos by Robert Miles on Youtube about AI safety and how AI will inevitably optimize against the metrics you score it by rather than the task you actually wanted it to do. Kind of like students cheating on tests. The point of the test was to measure how smart the student is, but the student isn't incentivized to be smart, they're incentivized to score well on tests. Learning is much more difficult than cheating, and so [some] students cheat on tests.

54

u/Galse22 Dec 05 '20

Well, If FPS was 300 it'd be set to 60... So yeah... That's be a downgrade.

49

u/[deleted] Dec 05 '20

if fps != 300 { fps = 300 }

upgrades_people_upgrades.jpg

26

u/unfunny_joker Dec 05 '20

while fps < 300 { fps++ }

6

u/botle Dec 05 '20

Increases the fps from 15 to 16.

→ More replies (2)

8

u/HattyJetty Dec 05 '20

I'd just set fps = Infinity for good measure

5

u/[deleted] Dec 05 '20

But optimization!

19

u/xmartissxs Dec 05 '20

while(true) fps++;

30

u/Ali3nat0r Dec 05 '20

Fps is now -2147483648. Oops

18

u/xmartissxs Dec 05 '20

At that point you would just start seeing into the future. Or the past, no one knows

2

u/atiedebee Mar 19 '22

And then the entire game stopped responding

27

u/healplease Dec 05 '20

unnessesary equality check here, it can make your game's FPS drop

7

u/Gonzo345 Dec 05 '20

Damn b0i

7

u/[deleted] Dec 06 '20

It is always 60fps, it just shows the same picture 4 frames in a row

13

u/ce-walalang Dec 06 '20

Image Transcription: Text Messages


[Screenshot from Discord.]

Logan: I solved our optimization problem

if fps != 60
  {
  fps = 60
  }

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

2

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 01 '21

Don't ask what I'm doing look at 25-day-old posts but I noticed there are no good humans, so -- Good human! <3

2

u/ce-walalang Jan 01 '21

haha thanks, fellow good human! :)

5

u/chronicideas Dec 06 '20

QA here.

There’s a potential bug here where if FPS is higher than 60 it would get decreased to 60.

I think it should be refactored to

if fps < 60
{
    fps = 60
}

3

u/veskoyyy Dec 06 '20

Modern problems. Modern solutions. Well played. Now go fix that COVID thing!

3

u/TrigamYT Dec 06 '20 edited Jun 05 '22

if (fps < 60) { fps = 60 }

3

u/sdriyaz712 Dec 06 '20

Python kids trying to use JavaScript

3

u/wktr_t Dec 06 '20

Whoever indents code like this can also kill.

2

u/AtlasJan Dec 06 '20

1TBS is exactly as it sounds.

3

u/ReduceHyperlinks Dec 06 '20

if fps > 60{ if fps != null { if true && false != true { var fpsdiff = 60 - fps; while fpsdiff > 0 { fps = fps + 1; fpsdiff = fpsdiff - 1; } } } }

2

u/[deleted] Dec 06 '20

What language is this even

2

u/cyberspacedweller Dec 06 '20

That’s just VSync. You’ll be capped at 60 even if you’re over with that logic.

2

u/evanlinjin Dec 06 '20

// I optimized it.

if fps < 60 { fps = 60 }

2

u/n3wsw3 Dec 06 '20

It should clearly be max(fps, 60) so if the fps was over 60 it doesn't get lowered.

2

u/ImpDoomlord Dec 06 '20

Lmao I actually tried this when I was a kid in Gamemaker. I did a check if the FPS dropped below 30 and set the target room speed even higher to compensate since I had no concept of delta time and everything I coded back then was frame rate locked. The result was an even more unstable laggy mess that would crash occasionally

2

u/[deleted] Dec 06 '20

My god this is revolutionary

1

u/Rudxain let let.let = 'let' Dec 10 '20

for (fps = 30; fps < Infinity; fps++){fps *= fps}

1

u/[deleted] Dec 26 '20

Holy grail number for fps

1

u/[deleted] Mar 09 '21

but somehow my screen's default latency setting is like 59.randomgibberish

1

u/cheesycheese24 Feb 03 '22

o p t i m i z a t i o n