Help section from before the user variable changes that broke all macros
Moderator: MacroQuest Developers
-
OnyxSkyDV
- a lesser mummy

- Posts: 46
- Joined: Wed Sep 18, 2002 1:02 pm
Post
by OnyxSkyDV » Thu Jul 03, 2003 12:38 am
Ok guys, this is killing me... subs don't work, it says it can't find labels, and the /doevents is not working for me either... Anyone want to look through this is show me where I am going wrong?
Thanks!
| ceramic.mac
|
| by OnyxSkyDV
|
| Combines Small block of clay, ceramic lining sketch, water flask, and a quality firing sheet.
|
| v65 is the combine status.
#define DelayValue v95
#define EndPause v90
#define FailedWait v85
#event CombineFail "You lacked the skills to fashion the items together."
#event CombineAlt "You have fashioned the items together to create an alternate product."
#event CombineWork "You have fashioned the items together to create something new!"
#event CombineEmpty "You must place items in this object in order to create something new."
#event CombineWrong "You cannot combine these items in this combiner type!"
#event MissingItem "Couldn't find a "
#event Skillup "You have become better at "
#chat tell
Sub Main
/press /
/press e
/press n
/press d
|Set the delay value
/varset DelayValue 1
|Set the EndPause value
/varset EndPause 0
|Set the FailedWait value
/varset FailedWait 0
/doevents flush
|Sub OpenPacks
|place the packs you want opened here.
| /echo opening packs
| /click left pack 1
| /click left pack 2
| /click left pack 3
| /click left pack 6
| /click left pack 7
|/return
:WheelLoop
/sendkey esc
/sendkey esc
/sendkey esc
/itemtarget Pottery Wheel
/face item
/delay 5
/click left item
/delay 5
/echo opening packs
/click right inventory 1
/delay 2
/click right inventory 2
/delay 2
/click right inventory 3
/delay 2
/click right inventory 6
/delay 2
/click right inventory 7
/delay 2
/click left enviro combine
/doevents
/varset v65 0
/sendkey down ctrl
|Get first component
/finditem "water flask"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick1
|Place water flask in Forge
/click left enviro 0
/delay $DelayValue
/if "$cursor(name)"=="Water Flask" /goto :ReClick1
|Get Second component
/finditem "small block of clay"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick2
|Place small block of clay in Forge
/click left enviro 1
/delay $DelayValue
/if "$cursor(name)"=="small block of clay" /goto :ReClick2
|Get third component
/finditem "ceramic lining sketch"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick3
|Place ceramic lining sketch in Forge
/click left enviro 2
/delay $DelayValue
/if "$cursor(name)"=="ceramic lining sketch" /goto :ReClick3
|Click the Combine button
/click left enviro combine
/doevents
:WaitCombine
/delay 4
/varadd FailedWait 1
/echo just did doevents
/echo $int($v65)
/if n $FailedWait>5 /goto :StopMacro
/echo just did failedwait loop count
/if n $v65==1 {
/goto :WheelLoop
} else
/if n $v65==2 {
/goto :KilnLoop
} else
/if n $v65==0 { /goto :WaitCombine }
/goto :StopMacro
/sendkey up ctrl
/return
|************end of pottery wheel section*****************
:KilnLoop
/sendkey esc
/sendkey esc
/sendkey esc
/itemtarget Kiln
/face item
/delay 5
/click left item
/delay 5
/echo opening packs
/click right inventory 1
/delay 2
/click right inventory 2
/delay 2
/click right inventory 3
/delay 2
/click right inventory 6
/delay 2
/click right inventory 7
/delay 2
/click left enviro combine
/doevents
/varset v65 0
/sendkey down ctrl
|Get first component
/finditem "unfired ceramic lining"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick4
|Place unfired ceramic lining in Forge
/click left enviro 0
/delay $DelayValue
/if "$cursor(name)"=="unfired ceramic lining" /goto :ReClick4
|Get Second component
/finditem "quality firing sheet"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick5
|Place quality firing sheet in Forge
/click left enviro 1
/delay $DelayValue
/if "$cursor(name)"=="quality firing sheet" /goto :ReClick5
|Click the Combine button
/click left enviro combine
:WaitCombine2
/delay 4
/varadd FailedWait 1
/if n $FailedWait>2 /goto :AutoDrop2
/if $cursor()==True {
/goto :AutoDrop2
} else /goto :WaitCombine2
|Drop everything in auto equip
:AutoDrop2
/if $cursor()==True {
/click left auto
/delay 4
/goto :AutoDrop2
}
/varset FailedWait 0
|Start a new Combine
/sendkey up ctrl
/goto :WheelLoop
/return
|***********end of kiln section**********************
Sub Event_CombineFail
/varset v65 1
/echo just did fail set
/return
Sub Event_CombineWork
/varset v65 2
/echo just did make set
/return
Sub Event_Chat
/endmacro
/return
:StopMacro
|insert stats display here.
/echo "Run time: $calc($running/60) min - Combines: $int($v1) - Skill ups: $int($v2)"
/zapvars
/click left enviro done
/sendkey up ctrl
/endmacro
/return
-
kagonis
- a hill giant

- Posts: 228
- Joined: Sat May 24, 2003 8:48 pm
Post
by kagonis » Thu Jul 03, 2003 1:14 am
When posting macro code, please use the [ code ] [ /code ] blocks to encapsulate your code, and disable smilies ;)
Anyway, I took a quick look at the code, indented it a bit while doing so, highlighted and commented the sections I found by skimming it.
Code: Select all
| ceramic.mac
|
| by OnyxSkyDV
|
| Combines Small block of clay, ceramic lining sketch, water flask, and a quality firing sheet.
|
| v65 is the combine status.
#define DelayValue v95
#define EndPause v90
#define FailedWait v85
#event CombineFail "You lacked the skills to fashion the items together."
#event CombineAlt "You have fashioned the items together to create an alternate product."
#event CombineWork "You have fashioned the items together to create something new!"
#event CombineEmpty "You must place items in this object in order to create something new."
#event CombineWrong "You cannot combine these items in this combiner type!"
#event MissingItem "Couldn't find a "
#event Skillup "You have become better at "
#chat tell
Sub Main
/press /
/press e
/press n
/press d
|Set the delay value
/varset DelayValue 1
|Set the EndPause value
/varset EndPause 0
|Set the FailedWait value
/varset FailedWait 0
/doevents flush
[color=orange]|Sub OpenPacks
|place the packs you want opened here.
| /echo opening packs
| /click left pack 1
| /click left pack 2
| /click left pack 3
| /click left pack 6
| /click left pack 7
|/return[/color]
[color=red]A Sub within a Sub doesn't work very well, I can see it is commented out though, so this is not causing trouble right here.[/color]
:WheelLoop
/sendkey esc
/sendkey esc
/sendkey esc
/itemtarget Pottery Wheel
/face item
/delay 5
/click left item
/delay 5
/echo opening packs
/click right inventory 1
/delay 2
/click right inventory 2
/delay 2
/click right inventory 3
/delay 2
/click right inventory 6
/delay 2
/click right inventory 7
/delay 2
/click left enviro combine
/doevents
/varset v65 0
/sendkey down ctrl
|Get first component
/finditem "water flask"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick1
|Place water flask in Forge
/click left enviro 0
/delay $DelayValue
/if "$cursor(name)"=="Water Flask" /goto :ReClick1
|Get Second component
/finditem "small block of clay"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick2
|Place small block of clay in Forge
/click left enviro 1
/delay $DelayValue
/if "$cursor(name)"=="small block of clay" /goto :ReClick2
|Get third component
/finditem "ceramic lining sketch"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick3
|Place ceramic lining sketch in Forge
/click left enviro 2
/delay $DelayValue
/if "$cursor(name)"=="ceramic lining sketch" /goto :ReClick3
|Click the Combine button
/click left enviro combine
/doevents
:WaitCombine
/delay 4
/varadd FailedWait 1
/echo just did doevents
/echo $int($v65)
/if n $FailedWait>5 /goto :StopMacro
/echo just did failedwait loop count
/if n $v65==1 {
/goto :WheelLoop
} else /if n $v65==2 {
/goto :KilnLoop
} else /if n $v65==0 /goto :WaitCombine
/goto :StopMacro
/sendkey up ctrl
[color=orange]/return[/color]
[color=red]/return exits your Sub, everything below this point is not executed (to my knowledge)[/color]
|************end of pottery wheel section*****************
:KilnLoop
/sendkey esc
/sendkey esc
/sendkey esc
/itemtarget Kiln
/face item
/delay 5
/click left item
/delay 5
/echo opening packs
/click right inventory 1
/delay 2
/click right inventory 2
/delay 2
/click right inventory 3
/delay 2
/click right inventory 6
/delay 2
/click right inventory 7
/delay 2
/click left enviro combine
/doevents
/varset v65 0
/sendkey down ctrl
|Get first component
/finditem "unfired ceramic lining"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick4
|Place unfired ceramic lining in Forge
/click left enviro 0
/delay $DelayValue
/if "$cursor(name)"=="unfired ceramic lining" /goto :ReClick4
|Get Second component
/finditem "quality firing sheet"
/delay $DelayValue
/if $cursor()!=True /goto :StopMacro
:ReClick5
|Place quality firing sheet in Forge
/click left enviro 1
/delay $DelayValue
/if "$cursor(name)"=="quality firing sheet" /goto :ReClick5
|Click the Combine button
/click left enviro combine
:WaitCombine2
/delay 4
/varadd FailedWait 1
/if n $FailedWait>2 /goto :AutoDrop2
/if $cursor()==True {
/goto :AutoDrop2
} else /goto :WaitCombine2
|Drop everything in auto equip
:AutoDrop2
/if $cursor()==True {
/click left auto
/delay 4
/goto :AutoDrop2
}
/varset FailedWait 0
|Start a new Combine
/sendkey up ctrl
/goto :WheelLoop
[color=orange]/return[/color]
[color=red]Here you meant to end your Main sub, from what I can understand from your macro[/color]
|***********end of kiln section**********************
Sub Event_CombineFail
/varset v65 1
/echo just did fail set
/return
Sub Event_CombineWork
/varset v65 2
/echo just did make set
/return
Sub Event_Chat
/endmacro
/return
[color=orange]:StopMacro
|insert stats display here.
/echo "Run time: $calc($running/60) min - Combines: $int($v1) - Skill ups: $int($v2)"
/zapvars
/click left enviro done
/sendkey up ctrl
/endmacro
/return[/color]
[color=red]This part is outside a sub[/color]
-
OnyxSkyDV
- a lesser mummy

- Posts: 46
- Joined: Wed Sep 18, 2002 1:02 pm
Post
by OnyxSkyDV » Thu Jul 03, 2003 11:33 am
Right on, I was missing some basic layout rules I can see.
The openpacks sub was not working before, which is why I commented it out, but I can see that being inside the sub main would throw it.
The /return in the middle I threw in last night while trying to make it work, which it did not. I will remove it as it is not helping.
Thanks so much for the pointers, I will go clean it up and see if I can get it to work!
OnyxSkyDV
-
Valerian
- a grimling bloodguard

- Posts: 709
- Joined: Sun Jul 28, 2002 3:29 am
Post
by Valerian » Thu Jul 03, 2003 5:28 pm
Just as a side note, clean code is good. If your code looks clean, and follows some form of indention scheme that is constant throughout the code, it's MUCH easier to spot bugs and see problems in it.
Everyone has their own way of writing code, but most experienced coders have figured out ways to make their code more readable and easily followed, simply by placing tabs (or spaces) to indent code inside loops, blocks, etc...
As an example of the way I generally indent...
Code: Select all
Sub Mysub
/command 1
/command 2
:loop
/command 3
/if something==somethingelse {
/dothis
/dothat
} else {
/dotheotherthing
}
/dosomething
/if n something==1 /goto :loop
/return
*shrug* just a friendly nudge in the right direction, and this is just one way of many to make cleaner looking code

-
kagonis
- a hill giant

- Posts: 228
- Joined: Sat May 24, 2003 8:48 pm
Post
by kagonis » Thu Jul 03, 2003 6:04 pm
/agree
Clean code means the world when debugging.
Also while debugging, make a lot of /echo's througout the macro, that way you can more easily locate where something goes wrong.
Like, if you are unsure if a variable is set at a certain point in your macri, simply /echo $yourvariable
-
BlueSkies
- a ghoul

- Posts: 132
- Joined: Tue Oct 01, 2002 6:22 pm
Post
by BlueSkies » Thu Jul 03, 2003 6:14 pm
Also, having an intimate knowledge of what should be happening where in your code, and segregating functions to better support that, makes it very easy to spot where something goes wrong, when (not if) it does.
Don't be discouraged when your code does do something you didn't intend, and goes haywire and develops a mind of its own... I've been working with Jala on our main botting script now for a couple weeks, and every day it seems a host of problems crop up when we try to add new functionality....

Live your dreams! Blue Skies everyone
-
OnyxSkyDV
- a lesser mummy

- Posts: 46
- Joined: Wed Sep 18, 2002 1:02 pm
Post
by OnyxSkyDV » Fri Jul 04, 2003 10:41 am
Some strangeness, maybe you all can tell me if this is normal or not...
I finally got it cleaned up and running, and will post it after a few tweaks if anyone is interested.
I found the following:
Subs (including the events) would not run till I placed them about the Sub Main. It was like the parser could not read forward in the macro to find the sub and come back. but if it had seen the sub on the way by to the main, it could call back to them.
Same went for :labels. Could not read forward in the macro to them, but it made it difficult to try and place them earlier and jump past them...
The /Doevents did finally work, but it needed a /delay after the combine inorder for them to be caught. a fairly big one in the scheme of things (delay 5). So between putting the misc subs over the main, and adding the delay, I was able to get that part running.
Thanks everyone for the help they gave me with this, and let me know what you think about my findings, would love to hear if this is normal, or just some field of "weirdness: surrounding my computer. :)
OnyxSkyDV