#๐ Little problem with this little script
42 messages ยท Page 1 of 1 (latest)
@static tendon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
You didn't call the function click
thanks you for the reply He don't in the tutorial but it's working, how i can call the function ?
Hey @static tendon!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
!functions
When assigning a new name to a function, storing it in a container, or passing it as an argument, a common mistake made is to call the function. Instead of getting the actual function, you'll get its return value.
In Python you can treat function names just like any other variable. Assume there was a function called now that returns the current time. If you did x = now(), the current time would be assigned to x, but if you did x = now, the function now itself would be assigned to x. x and now would both equally reference the function.
Examples
# assigning new name
def foo():
return 'bar'
def spam():
return 'eggs'
baz = foo
baz() # returns 'bar'
ham = spam
ham() # returns 'eggs'
# storing in container
import math
functions = [math.sqrt, math.factorial, math.log]
functions[0](25) # returns 5.0
# the above equivalent to math.sqrt(25)
# passing as argument
class C:
builtin_open = staticmethod(open)
# open function is passed
# to the staticmethod class
def click():
Function code here...
click()
After defining a function you have to call it to run the code inside it
Can you send the error here ?
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.01)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
while keyboard.is_pressed('q')== False:
if pyautogui.pixel(601, 401) [0] == 0:
click(601, 401)
if pyautogui.pixel(691, 401) [0] == 0:
click(697, 401)
if pyautogui.pixel(785, 401) [0] == 0:
click(785, 401)
if pyautogui.pixel(840, 401) [0] == 0:
click(840, 401)
like that ?
does that look like the last line
i changed
Check the indentation it should be on the same level as
def click():
Also the function needs 2 arguments x and y
So tutorial is verry bad or what ? i have the same script page of him in the video
I'm not sure about that but all you have to do is call the function
You could just pass (0, 0) as arguments but it will click at 0, 0 on when starting
Which is the top left corner of the screen
def click(x,y):
win32api.SetCursorPos((601,401))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,601,401)
time.sleep(0.01) #le doigt est posรฉ sur le clik et attend 0.01 = pause
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,601,401)
better ? @fallow scaffold
What about the rest of the code
def click(x,y):
win32api.SetCursorPos((601,401))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,601,401)
time.sleep(0.01) #le doigt est posรฉ sur le clik et attend 0.01 = pause
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,601,401)
while keyboard.is_pressed('q')== False:
if pyautogui.pixel(601, 401) [0] == 0:
click(601, 401)
if pyautogui.pixel(691, 401) [0] == 0:
click(697, 401)
if pyautogui.pixel(785, 401) [0] == 0:
click(785, 401)
if pyautogui.pixel(840, 401) [0] == 0:
click(840, 401)
import pyautogui
import time
import keyboard
import win32api, win32con
#title 1 X: 601 Y: 401 RGB: ( 89, 90, 117)
#title 2 X: 697 Y: 401 RGB: ( 0, 0, 0)
#title 3 X: 785 Y: 401 RGB: ( 91, 93, 118)
#title 4 X: 840 Y: 401 RGB: ( 84, 86, 117)
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.01) #
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
while keyboard.is_pressed('q')== False:
if pyautogui.pixel(601, 401) [0] == 0:
click(601, 401)
if pyautogui.pixel(691, 401) [0] == 0:
click(697, 401)
if pyautogui.pixel(785, 401) [0] == 0:
click(785, 401)
if pyautogui.pixel(840, 401) [0] == 0:
click(840, 401)
click(0, 0)
lol sorry but it's not work @fallow scaffold
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
i understand nothing sorry, do you have better video tutorial for click and image recognition in python maybe ? @fallow scaffold
I think you should learn the basics first
!res
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
thank you for your help
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Little problem with this little script