Cant use def!?!?
I wanted a bot for a game and I found one on a forum.
And it seems like my sikuli can handle def command(or whatever it is). When i run it sikuli closes in like 1 sec then sikuli pop ups again leaving no error.
This is how some of the code looks:
def letsmine():
if mineiron == True:
if gamezone.
if mineiron == True:
if gamezone.
if mineiron == True:
if gamezone.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- danne95
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
a def on its own does nothing. It is only a piece of prepared code to be run by calling it.
Normally it is used to run the same workflow with different parameters and/or at different places in main workflow.
To run a def you have to call it like:
letsmine()
--- optimized version 1
assuming, that levelup() might change mineiron and/or more than one iron might exist in parallel
def letsmine():
if mineiron and gamezone.
if mineiron and gamezone.
if mineiron and gamezone.
--- optimized version 2
assuming, that mine iron is not changed and only one iron exists in game zone at one time
def letsmine():
if mineiron and
levelup()
the variables mineiron, iron, iron2, iron3 and waittime must be defined before calling lets mine
Revision history for this message
|
#3 |
When i added this i got this error message:
[error] Stoppad
[error] Ett fel uppstod på rad 221
[error] Felmeddelande: Traceback (most recent call last):
File "C:\Users\
if noore == 1: #if no ore founded call room changer module.
NameError: global name 'noore' is not defined
It says i have not defined noore but noore should not be defined. HELP :D
The code i added:
#Variables
global lastroom #Variable using moving to right room. Dont edit
global currentroom #Variable using moving to right room. Dont edit
global noore #Variable using moving to right room. Dont edit
def mine5_19(): #Room swap module
global lastroom
global currentroom
global noore
if gamezone.
currentroom = 1
lastroom = 1
if gamezone.
currentroom = 2
if lastroom == 1:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 3
if lastroom == 2:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 4
if lastroom == 3:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 5
if lastroom == 4:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 6
if lastroom == 5:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 7
if lastroom == 6:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 8
if lastroom == 7:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 9
if lastroom == 8:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 10
if lastroom == 9:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 1
if lastroom == 10:
while ui.exists(pic, 0): #while this image on screen it keep looping this.
letsmine() #Start mining module
fight() #run fight module
if closebutton.
fightover() #call fightover module and close it.
else:
if noore == 1: #if no ore founded call room changer module.
pass
Revision history for this message
|
#4 |
Uuups, you should have a look at lists and loops - makes code much shorter and more flexible ;-)
You only said, that noore is global. But nowhere it is getting a value like noore=1.
BTW: declaring a variable as global is only needed inside a def if you change its contents inside the def
x = 1 # x is global
def func():
print x # x is still global
def func1():
x = 5 # this x is local to the def
print x
def func2():
global x
x = 2
print x
print x # 1
func() # 1
print x # 1
func1() # 5
print x # 1
func2() # 2
print x # 2
Revision history for this message
|
#5 |
I do not understand. I did not write this code so I do not understand that much. Cant I just change something in my code instead of replace it?
Revision history for this message
|
#6 |
The piece of code, you are presenting here loops around
--- calling letsmine()
--- calling fight()
--- check fight is over
--- if not, change room
so some where in the other functions noore must get a value.
If you send me all the stuff zipped, I can have a look at it if you want.
Revision history for this message
|
#7 |
Ok, here's my script: http://
Thanks alot for helping me
Revision history for this message
|
#8 |
Sorry, you have implemented bot "versions" of letsmine().
I have commented out the harming stuff at line 210.
So noore was really never touched before.
download: http://
Revision history for this message
|
#9 |
so shall I delete this?
"""
# this function overrides the one before
# and never sets noore
def letsmine():
if mineiron == True:
if mineiron and (minezone.
"""
Revision history for this message
|
#10 |
can you take a look at this scrip to. It's for another job in the game i play and its the same problem as I posted in the beginning of this post: http://
Revision history for this message
|
#11 |
@ comment #9
using the block comment (""" before first line and """ after the last line of the stuff currently not needed) this part of the script is not active at the moment. I leave it up to you to delete it.
Revision history for this message
|
#12 |
@ comment #10
The script is syntactically ok.
I cannot judge what it does, but it should principally work, if the regions defined in the beginning of the script match on the screen and Sikuli finds the images.
Revision history for this message
|
#14 |
Ok, must be so ;-)
around line 189, you have to add global noore (as I mentioned in BTW at comment #4), since noore is set in lets mine().
should look like this:
def letsmine():
global noore
if mineiron == True:
Mind the indentation, must be the same as with the following if.
If you get indentation errors: faq 1800
Sorry, if I seem to be brutal: But if you want to manage such scripts (that are far from being programmed robust), you need some knowledge about how to write Python scripts.
Revision history for this message
|
#15 |
Ok thanks for the help ;D.
Can you send me a link to a good site where i kan learn to write Python script?
Revision history for this message
|
#16 |
I cannot give you any recommendations, since I never looked into such stuff.
If you have any knowledge in any programming/
mylanaguage versus python
or
python tutorial
Revision history for this message
|
#17 |
go step by step danne thats what i do at the moment but still couldn't fix the problem :(
iron = Pattern(
iron2 = Pattern(
copper = Pattern(
copper2 = Pattern(
bronze = Pattern(
bronze2 = Pattern(
gamezone = Region(
myself = ""L.png""
waittime = 10
mineiron = True
minecopper = True
minebronze = True
minetin = True
global lastroom
global currentroom
global noore
def mine9_m23)():
global lastroom
global currentroom
global noore
if gamezone.
currentroom = 1
lastroom = 1
wait (2)
if gamezone.
currentroom = 2
if lastroom == 1:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 3
if lastroom == 2:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 4
if lastroom == 3:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 5
if lastroom == 4:
wait (2)
else:
if currentroom == lastroom:
if gamezone.
currentroom = 6
if lastroom == 5:
else:
if currentroom == lastroom:
if gamezone.
currentroom = 1
if lastroom == 6:
gamezone.
def fightover():
if gamezone.
wait(2)
else:
pass
def fight(): #Fight module
while gamezone.
if gamezone.
if gamezone.
wait(1)
else:
if gamezone.
if gamezone.
def levelup():
if gamezone.
else:
pass
def letsmine(): #Mining module
global noore
if mineiron == True:
if gamezone.
noore = 0
if mineiron == True:
if gamezone.
noore = 0
#COPPER
if minecopper == True:
if gamezone.
noore = 0
if minecopper == True:
if gamezone.
noore = 0
#BRONZE
if minebronze == True:
if gamezone.
noore = 0
if minebronze == True:
if gamezone.
noore = 0
else:
noore = 1
pass
while gamezone.
letsmine() #Start mining module
fight() #run fight module
if gamezone.
fightover()
else:
if noore == 1:
pass
-------
[error] Stopped
[error] Error message: IndentationError: ('unindent does not match any outer indentation level', ('C:\\Users\