[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  always come out this erro!! parameter is always nil!!Why?

always come out this erro!! parameter is always nil!!Why?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Lucas828   (12 posts)  [Biography] bio
Date Thu 04 Jun 2009 12:04 AM (UTC)
Message
Run-time error
World: myworld
Immediate execution
[string "Script file"]:5: bad argument #1 to 'GetVariable' (string expected, got nil)
stack traceback:
[C]: in function 'GetVariable'
[string "Script file"]:5: in function 'mywork'
[string "Trigger: "]:1: in main chunk
Error context in script:
1 : function mywork(var1)
2 : --print (_VERSION);
3 :
4 :
5*: local v = GetVariable(var1);
6 : local mymaster = GetVariable("master");
7 : local myskills = GetVariable("skills");
8 :
9 : --print (mymaster);

I am newbie.Just want to trigger a patten and pass the matched content to function mywork.
why the var1 is always nil? I am confused, because I can see the matched content when choose the send to output!!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 04 Jun 2009 12:21 AM (UTC)
Message
Can you show the trigger please? http://mushclient.com/copying

I am guessing you are calling mywork from the trigger. Triggers take 3 arguments (or 4 in Lua if you want), like this:


function mywork (name, line, wildcards, styles)

local v = GetVariable(wildcards [1]);

end -- function


The third argument is the array of wildcards (the first one is the trigger name, and the second one is the matching line). Thus the first wildcard is wildcards [1]. However that doesn't totally explain what you are seeing, because var1 in your case would have been the trigger name. If you show the whole trigger it might become clearer.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #2 on Thu 04 Jun 2009 12:33 AM (UTC)
Message
<triggers
muclient_version="4.12"
world_file_version="15"
date_saved="2009-06-03 23:26:14"
>
<trigger
enabled="y"
lines_to_match="2"
match="*hell*"
send_to="12"
sequence="100"
>
<send>mywork "%2";</send>
</trigger>
</triggers>
</muclient>
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #3 on Thu 04 Jun 2009 12:42 AM (UTC)
Message
yes, you are right, I just simply pass the %1 as the parameter to function mywork.

previously, I use zmud. this is the first i get in touch with mushclient. what is tigger name and line? why I need to pass these to function?


I need some simple example, in *.lua files to study mushclient.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Thu 04 Jun 2009 04:27 AM (UTC)
Message
You didn't copy the trigger as I suggested in the link http://mushclient.com/copying did you? Otherwise the date and time wouldn't be there.

Quote:

what is tigger name and line? why I need to pass these to function?


You are really combining two approaches here. Read up on http://mushclient.com/scripting for more details.

One approach is to use "send to script" (which you did), in which case the logical thing is to put the script instructions in the send box itself.

The other approach is to put the function name into the "script" box in the trigger, in which case MUSHclient passes the function name, and matching line to the script. You don't have to do it.

The trigger below demonstrates that (see http://mushclient.com/pasting for how to copy that back into the client):


<triggers>
  <trigger
   enabled="y"
   match="*hell*"
   script="myworld"
   sequence="100"
  >
  </trigger>
</triggers>


However more simply, just do what you want in the trigger send box, like this:


<triggers>
  <trigger
   enabled="y"
   match="*hell*"
   send_to="12"
   sequence="100"
  >
  <send>

local v = GetVariable("%1")
local mymaster = GetVariable("master")
local myskills = GetVariable("skills")

print (mymaster)
print (myskills)
print (v)

</send>
  </trigger>
</triggers>


Now you don't need a script file at all, and you don't need to call a function - just do it all inline.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #5 on Thu 04 Jun 2009 06:48 AM (UTC)
Message
the result is same.

I copy the function script in the send box.

when I type say yousayhellooo

and choose to send to script

v is still nil

when I choose to send to output,

the result appears on the screen:

local v = GetVariable("ooo");
local mymaster = GetVariable("master")
local myskills = GetVariable("skills")

print (v)
print (mymaster)
print (myskills)




<triggers>
<trigger
enabled="y"
match="*hell*"
send_to="2"
sequence="100"
>
<send>

local v = GetVariable("%2");
local mymaster = GetVariable("master")
local myskills = GetVariable("skills")

print (v)
print (mymaster)
print (myskills)
</send>
</trigger>
</triggers>

[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 04 Jun 2009 08:14 AM (UTC)
Message
OK, you say v is nil. Does the variable "ooo" actually exist? If not, v will be nil.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #7 on Thu 04 Jun 2009 08:26 AM (UTC)
Message
Yes, "ooo" exists!

If I choose to send to output.

When I type say yousayhellooo.

I can see the "ooo" on the screen!

But if I choose to send to script. the v is nil.

why?

Need I have to register the mushclient?
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #8 on Thu 04 Jun 2009 08:31 AM (UTC)
Message
oh, the question is that GetVariable does fail.

when choose to send to script.

print(%2);--that works, show the "ooo" on the screen

local v = GetVariable(%2);-- nil appears!
[Go to top] top

Posted by Lucas828   (12 posts)  [Biography] bio
Date Reply #9 on Thu 04 Jun 2009 08:40 AM (UTC)
Message
yes, GetVariable(%2) failed!

local v = %2;
print (v); -- that works!!

thanks Nick!!
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #10 on Wed 17 Jun 2009 04:34 AM (UTC)
Message
You still need to use quotes around the %num for the variables.

The %1 and %2 are directly replaced with whatever is captured. This means that it is not displayed as a string, but swapped out entirely. If the second parameter matches "foo", then here is how the following will show up when processed:

local v = GetVariable(%2)
becomes
local v = GetVariable(foo)

local v = GetVariable("%2)
becomes
local v = GetVariable("foo")

The first example will then attempt to pass the string stored in the variable named foo to the GetVariable function. Since this is not set, nil is passed to the function, causing the error.

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


27,144 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]