Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error with variables 3.8
#3
full code just for the heck of it
#afktool_v0.0.2
#include lib
import multiprocessing
import time as t
from pynput.mouse import Button, Controller
#init the mouse emulator
mouse = Controller()
#program info print
print("please note this will repetedly click the mouse. anywhere you have the mouse will be clicked 1 time a second")
print("afkTool version is in beta 0.0.2")
print("this tool is made to afk farm on a exp. mob farm in minecraft")
print("if you encounter an error that doesnt stop the program /n press cntl and c on this window and contact the devs")
print("beta testers:")
print("none yet. why is this here?")
#global var def
stopTread = False
err = False
#function to read user input for when running
def main_u_input():
    input("press any key to either abort or continue once completed")
    stopThread = True
#main function
def main_thread(tSet, delaySet=1):
    for i in range(0,tSet):
        iterationsLeft = tSet - int(i)
        print("time left in seconds {}. press ctrl+c on this window to quit".format(iterationsLeft))
        mouse.click(Button.left,1)
        if(stopThread == True):
            print("aborting")
            break
        else:
            t.sleep(delaySet)
#function to get user input on wheathe to continue
def get_mode():
    print("pick one of the following:")
    print("0 = quit")
    print("1 = run")
    m = input("please type the corresponding number and press enter>_")
    try:
        m = int(m)
    except ValueError:
        print("invalid input. try again")
        m = getMode()
    return m
#function to get user input for time needs
def get_time():
    print("enter 1 for seconds")
    print("enter 2 for minutes")
    print("enter 3 for hours")
    timeTyp = input("please enter one of the coresponding numbers> ")
    timeLen = input("please enter how long you want to run> ")
    timeDel = input("please enter how long you want the delay between clicks in miliseconds or d for default> ")
    try:
        timeTyp = int(timeTyp)
        timeLen = int(timeLen)
        try:
            timeDel = float(timeDel*1000)
        except ValueError:
            if(timeDel.lower().strip(" ") == "d"):
                td = 1.0
            else:
                err = True
        if(timeTyp == 1):
            tl = timeTyp
        elif(timeTyp == 2):
            tl = timeTyp * 60
        elif(timeTyp == 3):
            tl = timeTyp * 3600
        if(err == True):
            raise ValueError
    except ValueError:
        print("invalid input. try again")
        tl, td = get_time()
    return tl, td
#main logic
if(__name__ == "__main__"):
    while(True):
        mode = get_mode()
        if(mode == 1):
            t, d = get_time()
            p = multiprocessing.Process(target=main_thread, args=(t, d))
            p.start()
            main_u_input()
            p.join()
        elif(mode == 0):
            break
        else:
            print("invalid input try again")
            continue
    quit()
and the error output
Traceback (most recent call last):
File "C:\Users\Owner\Documents\PythonScripts\AfkTool\afkToolv0_0_2.py", line 80, in <module>
t, d = get_time()
File "C:\Users\Owner\Documents\PythonScripts\AfkTool\afkToolv0_0_2.py", line 69, in get_time
if(err == True):
UnboundLocalError: local variable 'err' referenced before assignment
Reply


Messages In This Thread
error with variables 3.8 - by jusrosetyler1123 - Dec-18-2019, 05:52 AM
RE: error with variables 3.8 - by buran - Dec-18-2019, 07:23 AM
RE: error with variables 3.8 - by jusrosetyler1123 - Dec-18-2019, 01:38 PM
RE: error with variables 3.8 - by buran - Dec-18-2019, 03:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to multiply two variables, but I get an error LeqendFire 3 3,001 Aug-09-2020, 03:52 PM
Last Post: LeqendFire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020