#๐Ÿ”’ Little problem with this little script

42 messages ยท Page 1 of 1 (latest)

hearty ploverBOT
#

@static tendon

Python help channel opened

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.

fallow scaffold
#

You didn't call the function click

static tendon
fallow scaffold
#
click()
#

Add to the last line

#

Outside the function

hearty ploverBOT
#

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.
static tendon
#

!functions

hearty ploverBOT
#
Calling vs. referencing 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
static tendon
#

i don't understand sorry, i add ```py
click()

#

in the last line but it's an error

fallow scaffold
#
def click():
      Function  code here...

click()
#

After defining a function you have to call it to run the code inside it

fallow scaffold
static tendon
#
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 ?

wicked creek
#

does that look like the last line

static tendon
#

i changed

fallow scaffold
#

Check the indentation it should be on the same level as
def click():

#

Also the function needs 2 arguments x and y

static tendon
#

So tutorial is verry bad or what ? i have the same script page of him in the video

fallow scaffold
#

Which is the top left corner of the screen

static tendon
#
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

fallow scaffold
#

What about the rest of the code

static tendon
#
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)
fallow scaffold
#

You just have to do

click(0, 0)

At the end of the file , outside the function

static tendon
#
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

fallow scaffold
#

Check the indentation

#

It should be on the same level as def click ()

#

!indent

hearty ploverBOT
#
Indentation

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

static tendon
#

i understand nothing sorry, do you have better video tutorial for click and image recognition in python maybe ? @fallow scaffold

fallow scaffold
#

!res

hearty ploverBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

static tendon
hearty ploverBOT
#
Python help channel closed

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