ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: UoLugnutz on February 17, 2010, 07:11:36 AM

Title: Question about %0
Post 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

Code: [Select]
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
Code: [Select]
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!


Title: Re: Question about %0
Post by: Cerveza on February 17, 2010, 07:26:56 AM
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.
Title: Re: Question about %0
Post by: 12TimesOver on February 17, 2010, 07:27:12 AM
%0 is the value of the number of criteria you send a sub. For example if you say:

Code: [Select]
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!
Title: Re: Question about %0
Post by: Cerveza on February 17, 2010, 07:29:27 AM
He so sloooow... heh

Quote from: EasyUO Docs
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.
Title: Re: Question about %0
Post by: 12TimesOver on February 17, 2010, 07:31:53 AM
LOL, ahhh parameters was the word I was having a hard time thinking of so I said values. Feels like a Monday.

Title: Re: Question about %0
Post by: Cerveza on February 17, 2010, 07:35:08 AM
See I learned them as arguments.

Quote from: Dictionary
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.

Quote from: Some script thingy
#  Within the script, we refer to the first argument as $1, the second argument as $2, and so on

Title: Re: Question about %0
Post by: UoLugnutz on February 17, 2010, 08:22:51 AM
Thanks for the quick response. I kinda thought that is what it was but was stumped by the
Code: [Select]
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?
Title: Re: Question about %0
Post by: 12TimesOver on February 17, 2010, 08:32:12 AM
Because one could call the sub with no arguments thus the backpack would still get opened but not moved to !x !y.

X
Title: Re: Question about %0
Post by: UoLugnutz on February 17, 2010, 08:46:07 AM
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!
Title: Re: Question about %0
Post by: Paulonius on February 18, 2010, 12:43:33 PM
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.