The Farmer Was Replaced

The Farmer Was Replaced

Shabazza 12 Dec, 2024 @ 4:08pm
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?
< >
Showing 1-5 of 5 comments
umop-apisdn 12 Dec, 2024 @ 4:11pm 
Originally posted by Shabazza:
"x = 0 and (y == 0 or y == 1)"
"x = 1 and (y == 0 or y == 1)"

"=" is assignment.
"==" is comparison.
Timon  [developer] 13 Dec, 2024 @ 1:20am 
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.
Shabazza 13 Dec, 2024 @ 12:24pm 
Originally posted by umop-apisdn:
Originally posted by 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.



Originally posted by 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...
Last edited by Shabazza; 13 Dec, 2024 @ 12:24pm
Procerus 25 Dec, 2024 @ 9:25pm 
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.
Procerus 25 Dec, 2024 @ 9:39pm 
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]
Last edited by Procerus; 25 Dec, 2024 @ 9:42pm
< >
Showing 1-5 of 5 comments
Per page: 1530 50