ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Crisis on February 17, 2014, 03:59:01 PM
-
Ok I have some time and I really need to understand how to implement a proper gumpwait. I am using the one that 12XOver posted when he was helping me with gumpwaits and I want to understand how to use it. I have so many script ideas and not enough talent yet to implement them. I am quoting his post from this thread http://www.scriptuo.com/index.php?topic=12006.msg101293#msg101293
I am opening a new thread to make things easier. 8)
That's why a good Gumpwait sub should be able to use both Gumpname and Gumpsize :)
The issue with relying on Gumpname is that there are so many different gumps called "generic_gump". Adding an optional gumpsize to the wait sub gives that added flexibility for when you really want to make sure.
-----
Crisis - The issue with that first one is that it's not waiting until there is a gump, it's waiting for a 5 count only. What if the gump doesn't come up until the 6 count, well now your script is broken.
A basic gump wait sub needs to follow some basic gump wait logic:
sub gumpwait
1) tell me what gump to wait for via name and/or size
2) set an amount of time to keep looking for the gump before deciding it ain't comin'
3) keep looking for that gump until it either shows up or the amount of time has expired
4) tell the rest of the script what happened
return
This is all my example sub above is doing.
;#######################
;SUB XIIxGumpWait
;#######################
; %1 = Required: Gumpname 1
; %2 = Required only if using Gumpsize: Gumpname 2
; %3 = Optional: Gumpsize
; Returns #TRUE if gump occured before timeout, #FALSE if timeout occured
sub XIIxGumpWait
namespace push
namespace local nsXIIxGumpWait
This is creating the sub and giving it a namespace so that none of it's variables will conflict with the rest of the variables in the script that's calling it
set !gName1 %1
set !gName2 %2
set !gSize %3
1) tell me what gump to wait for via name and/or size
set !_time #SCNT
while #SCNT <= !_time + 5
2) set an amount of time to keep looking for the gump before deciding it ain't comin'
while #SCNT <= !_time + 5
{
if %0 > 2
{
if ( #CONTNAME = !gName1 && #CONTSIZE = !gSize ) || ( #CONTNAME = !gName2 && #CONTSIZE = !gSize )
{
namespace clear
namespace pop
return #TRUE
}
}
else
{
if #CONTNAME = !gName1 || #CONTNAME = !gName2
{
namespace clear
namespace pop
return #TRUE
}
}
}
3) keep looking for that gump until it either shows up or the amount of time has expired
4) tell the rest of the script that it did come up
namespace clear
namespace pop
Cleanup my namespace
return #FALSE
4) tell the rest of the script that it DID NOT come up
So if using this as is, I would use the wait kind of like this?
gosub XIIxGumpWait
Would I list a time after like this?
gosub XIIxGumpWait 20
On the name part, would this section need to be changed at all?
set !gName1 %1
set !gName2 %2
set !gSize %3
I set a gumpsize on my scripts so how would that affect !gName2 %2
Would I need to use %3 on scripts like carpentry which has gumps for tinkering and carpentry?
-
Hey Crisis!
The reason for a Gumpwait sub is that the time could fluctuate for different people. What might take .1 seconds for you to open a menu could take .6 seconds for me. The idea of a Gumpwait is to say "hang out until you see the "gump" with the following attributes then move along". This way it doesn't matter how long the gump takes to open, you'll be waiting for it.
Would I list a time after like this?
Code: Select All | Copy To Clipboard
gosub XIIxGumpWait 20
Nope, because you don't really know what the time should be. You want to pass the name of the gump and the size (because the name is usually the same for many gumps) so, for example, if you were using my sub, the gump name was "generic_gump" and the size was 100x100:
Gosub XIIxGumpWait generic_gump generic_gump 100_100
Note that my Gumpwait uses two different options for the Gump name (this name OR that name) which is probably not necessary but is an idea I stole from TM's way back when I was still learning and it stuck lol.
On the name part, would this section need to be changed at all?
Code: Select All | Copy To Clipboard
set !gName1 %1
set !gName2 %2
set !gSize %
I set a gumpsize on my scripts so how would that affect !gName2 %2
You don't change anything in the sub, you pass your variable to it. So, for example, if you set your gump name to something like %CarpMenuName and the size to something like %CarpMenuSize you would call the sub like:
gosub XIIxGumpWait %CarpMenuName %CarpMenuName %CarpMenuSize
Would I need to use %3 on scripts like carpentry which has gumps for tinkering and carpentry?
It's always best to use both the name and the size. When you are using two different skills with identical menu sizes then this can get tricky determining the difference between one or the other so you need to build logic around this in your code but this has no bearing on your gumpwait sub, it's job is ONLY to wait for a gump that you tell it to wait for then report back to the body of the script whether it happened or not.
X
-
Neo have a interesting gumpwait as well in his Ter_mur_lumber or Miner
gosub gumpwait container_gump 144_212 N/A
or
gosub gumpwait N/A N/A %tool_bag
;======= Gumpwait Sub =======
sub gumpwait
namespace push
namespace local gumpwait
set !name %1
set !size %2
set !id %3
set !condcnt 0
set !nameyes #true
set !sizeyes #true
set !idyes #true
set !timeout #SCNT + 5
if !name = N/A
{
set !condcnt !condcnt + 1
set !nameyes #false
}
if !size = N/A
{
set !condcnt !condcnt + 1
set !sizeyes #false
}
if !id = N/A
{
set !condcnt !condcnt + 1
set !idyes #false
}
repeat
if #contname = !name && !nameyes = #true
{
set !condcnt !condcnt + 1
set !nameyes #false
}
if #contsize = !size && !sizeyes = #true
{
set !condcnt !condcnt + 1
set !sizeyes #false
}
if #contid = !id && !idyes = #true
{
set !condcnt !condcnt + 1
set !idyes #false
}
until !condcnt = 3 || #scnt > !timeout
if !condcnt = 3
{
namespace pop
return #true
}
namespace pop
return #false
Must be solid because it work never hang on the gump. :))
-
You don't change anything in the sub, you pass your variable to it. So, for example, if you set your gump name to something like %CarpMenuName and the size to something like %CarpMenuSize you would call the sub like:
gosub XIIxGumpWait %CarpMenuName %CarpMenuName %CarpMenuSize
Would I need to use %3 on scripts like carpentry which has gumps for tinkering and carpentry?
It's always best to use both the name and the size. When you are using two different skills with identical menu sizes then this can get tricky determining the difference between one or the other so you need to build logic around this in your code but this has no bearing on your gumpwait sub, it's job is ONLY to wait for a gump that you tell it to wait for then report back to the body of the script whether it happened or not.
X
Could I do something like this then?
gosub XIIxGumpWait CarpMenu CarpMenu 530_497
for carpentry tool
and
gosub XIIxGumpWait TinkMenu TinkMenu 530_497
for the tinker tool?
One other question, since this is in your subs section, it is available to use in other's scripts as long as credit is given such as leaving the name SUB XIIxGumpWait?
-
Yep, yep again, and yep :)
-
Tinkering Menu or carpentry menu have the same #CONTNAME
#CONTNAME generic_gump 530_497
So you just make up a name
gosub XIIxGumpWait CarpMenu CarpMenu 530_497
or does the name need to be precise.
gosub XIIxGumpWait generic_gump generic_gump 530_497