ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: UoLugnutz on February 17, 2010, 07:11:36 AM
-
I'm just in the middle of writing my first script and would like to add a few snippets. Why re event the wheel but I don't want to use them until I understand completely what I am using. An example is I want to make sure my backpack is open and if it is not open to open it to a set position. TM has this snippet that works perfect
gosub TM_CheckBackpack 200 200
sub TM_CheckBackpack
namespace push
namespace local CP
set !cnt %0
set !x %1
set !y %2
finditem * C_ , #BACKPACKID
if #FINDKIND = -1
{
event macro 8 7 ; open backpackid
gosub GumpAndSizeWait container_gump 230_204
if !cnt > 0
{
contpos !x !y
wait 10
}
}
namespace pop
return
Its the set !cnt %0
line. What is the value of %0? I used the search button but didn't find what I was looking for. Thanks in advance!
-
It's how many arguments your sending to the sub...
gosub somesubroutine one two three four five
that would result a %0 of 5 because you sent 5 arguments to the sub.
gosub somesubroutine cerv really rox
that would result in %0 being 3 because of the 3 arguments sent.
-
%0 is the value of the number of criteria you send a sub. For example if you say:
gosub sub1 %Value %Value2 %Value3
you are sending three values thus %0 = 3
Hope that helps.
X
<edit> I see Cerv beat me to it LOL. Oh well, there's two examples for ya!
-
He so sloooow... heh
gosub
The gosub command transfers the execution to a sub with the name given by the parameter.
gosub sub_name
Parameters can be added after the sub name. They will be transfered in the variables %1, %2, and so on. The variable %0 holds the number of parameters passed.
-
LOL, ahhh parameters was the word I was having a hard time thinking of so I said values. Feels like a Monday.
-
See I learned them as arguments.
9. Computers. a variable in a program, to which a value will be assigned when the program is run: often given in parentheses following a function name and used to calculate the function.
# Within the script, we refer to the first argument as $1, the second argument as $2, and so on
-
Thanks for the quick response. I kinda thought that is what it was but was stumped by the
If !cnt > 0 line
. Since !cnt is set to 2 it will always be greater then 0. When will it ever fail? If it can never fail why have it?
-
Because one could call the sub with no arguments thus the backpack would still get opened but not moved to !x !y.
X
-
Because one could call the sub with no arguments thus the backpack would still get opened but not moved to !x !y.
X
Fug me! That almost seems obvious. Need to stop thinking of the specific use of the sub I could use it for and more a general sense of what the sub can be used for. The whole "What if" thing.
Thanks again for all the help!
-
hmm, I didn't realize that you could pull the value of 0% either. Nice way to control the performance of a sub that accepts varying numbers of arguments/parameters/values/whatevers.