The Farmer Was Replaced

The Farmer Was Replaced

IF with parenthesis not working?
Can someone please tell me why this is not working?
https://ibb.co/GxS4Br7

I say it shall plant a pumpkin when
"x = 0 and (y == 0 or y == 1)"
and when
"x = 1 and (y == 0 or y == 1)"

I checked the debug output for the actual xPos / yPos variables and they are correctly showing the coordinates.
But it always evaluates the if() line to be TRUE for ALL fields, even when the drone is at
x==2 or Y == 3.

Why? Am i too tired right now to see it?
< >
1-5 van 5 reacties weergegeven
Origineel geplaatst door Shabazza:
"x = 0 and (y == 0 or y == 1)"
"x = 1 and (y == 0 or y == 1)"

"=" is assignment.
"==" is comparison.
Timon  [ontwikkelaar] 13 dec 2024 om 1:20 
Each function has it's own scope so xPos and yPos in prepare are not the same variables as xPos and yPos in updatePosition. They are local variables that only exist inside that def block.
Origineel geplaatst door umop-apisdn:
Origineel geplaatst door Shabazza:
"x = 0 and (y == 0 or y == 1)"
"x = 1 and (y == 0 or y == 1)"

"=" is assignment.
"==" is comparison.
That was just me being not precise when writing the post.



Origineel geplaatst door Timon:
Each function has it's own scope so xPos and yPos in prepare are not the same variables as xPos and yPos in updatePosition. They are local variables that only exist inside that def block.
Right.. next question: Does the game "pass by reference" ?
Can I pass the xPos, yPos to my updatePosition and update those variables, or will it again create new instances?
Then I guess I have to use a global dictionary for the position...which I have not unlocked yet.
The game says, dicts are using references. Hm. Hm.
I was just trying to keep calls at a minimum.
Therefore, I fetch those values once, if possible at the highest possible scope.
Old habit of an embedded developer...
Laatst bewerkt door Shabazza; 13 dec 2024 om 12:24
Assuming it's running python under the hood and not just emulating the syntax it's pass by object reference. So if it's a mutable object like a list or dict it will be updated because it's the same object you are pointing to. If it's immutable like an integer or string, changing the value will assign a new object and the reference outside of your function will still point to the old object and will not change.
Seems to work as expected.

def change_string(s): s = "new string" def change_list(l): l.append(3) string_test = "old string" list_test = [1, 2] change_string(string_test) change_list(list_test) print(string_test) print(list_test)

This code outputs:
old string
[1,2,3]
Laatst bewerkt door Procerus; 25 dec 2024 om 21:42
< >
1-5 van 5 reacties weergegeven
Per pagina: 1530 50