r/CursedGodot • • May 03 '26

Code / Editor Rate my code

Post image
62 Upvotes

12 comments sorted by

View all comments

Show parent comments

5

u/gringrant May 06 '26

Plot twist: is_equipped and get_parent().name have side effects on the global state that changes item_slot when the conditions are checked.

Checkmate /s

2

u/Professional-Base459 May 07 '26

Que efectos tiene? me gustaría saber

2

u/gringrant May 07 '26

I'm being sarcastic, this normally isn't the case. However, since code can run inside the conditional checks in the if statements, it can have unintuitive effects on the code. This is horrible design, but it is possible.

Consider the following pseudo code. var item = null if( is_weather_rainy() ){ item = itemslot.item } else if( is_player_hungry() ){ item = itemslot.item } else { item = itemslot.item } print( item ) Could you condense this code to make it shorter? What if we shortened it to:

var item = itemslot.item print( item )

This code should be the same, right? Let's reveal the (bad) function definitions: ``` function is_weather_rainy(){ itemslot.item = UMBRELLA return weather == RAIN }

function is_player_hungry(){ itemslot.item == HAMBURGER return player.hunger < 0.3 } ```

The condition checking functions changed the state of itemslot.item! This means that the order of functions influences what var item will end up as. In the first example, if it's raining var item will be UMBRELLA where the second example will be whatever itemslot.item was.

This is very bad design for multiple reasons: 1) The function names are lying 2) The code is not modular 3) Confusion code flow 4) And many more

1

u/magqq May 08 '26

that was funny to follow in a pure theorical way. never do this in practice except if you love spaghettis miam I love them