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 / 5 のコメントを表示
Shabazza の投稿を引用:
"x = 0 and (y == 0 or y == 1)"
"x = 1 and (y == 0 or y == 1)"

"=" is assignment.
"==" is comparison.
Timon  [開発者] 2024年12月13日 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.
Shabazza 2024年12月13日 12時24分 
umop-apisdn の投稿を引用:
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.



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...
最近の変更はShabazzaが行いました; 2024年12月13日 12時24分
Procerus 2024年12月25日 21時25分 
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 2024年12月25日 21時39分 
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]
最近の変更はProcerusが行いました; 2024年12月25日 21時42分
< >
1-5 / 5 のコメントを表示
ページ毎: 1530 50

投稿日: 2024年12月12日 16時08分
投稿数: 5