Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ New to MUSHclient

New to MUSHclient

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


Pages: 1  2  3 4  5  

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #30 on Wed 07 Dec 2005 01:51 AM (UTC)
Message
Lua tends to use the variable named _ as a temporary variable. Since variables can start with an underscore, a variable name of only an underscore is used to show an unimportant variable.

You could rewrite it as:


 for key, value in ipairs (cures) do

 -- blah blah

 end -- for loop


Both the "pairs" and "ipairs" functions iterate over a table, returning for each iteration the key and value from that entry.

In the case of a numeric table, the key will simply be the numbers 1, 2, 3 etc. so that was why I put it into the "_" variable.


Read my writeup on Lua tables here:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6036

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #31 on Fri 06 Jan 2006 11:41 PM (UTC)
Message
I've just been able to start working on this script after a long time that I wasn't able to and I am having a problem. Whenever I try to send something to the script it always says "Send-to-script cannot execute because scripting is not enabled." even though the enable script button on config scripts is always checked. Any idea what my problem is?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #32 on Sat 07 Jan 2006 11:21 PM (UTC)
Message
If there is an error in your script it is disabled (as it couldn't be processed) until you fix it and "reload script file".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #33 on Sun 08 Jan 2006 03:15 AM (UTC)

Amended on Sun 08 Jan 2006 03:56 AM (UTC) by Gid

Message
Here's what I have in my script file.

afflicted_by = {} -- table of current afflictions
applying = false -- are we currently applying a salve?

-- cures for afflictions, put in order you want them cured

salvecures: = {
{ name = "anorexia" , cure = "epidermal" },
{ name = "silerisdef" , cure = "sileris" },
{ name = "legrest1" , cure = "restoration" },
{ name = "legrest2" , cure = "restoration" },
{ name = "legmend2" , cure = "mending" },
{ name = "legmend2" , cure = "mending" },
{ name = "headrest" , cure = "restoration" },
{ name = "armrest1" , cure = "restoration" },
{ name = "armrest2" , cure = "restoration" },
{ name = "armmend1" , cure = "mending" },
{ name = "armmend2" , cure = "mending" },
{ name = "torsorest" , cure = "restoration" },
{ name = "burning" , cure = "mending" },
{ name = "shivering" , cure = "caloric" },
{ name = "caloricdef" , cure = "caloric" },
{ name = "massdef" , cure = "mass" },
} - end of salvecures

function do_cure ()

if applying or
afflicted_by.food or
afflicted_by.anorexia then
return
end -- if can't do it yet

-- find most urgent one to cure

for _, v in ipairs (salvecures) do
if afflicted_by [v.name] then
if v.cure ~= "" then -- some afflictions might not have cures
Send ("apply ", v.cure) -- apply it
applying = true
return -- done
end -- of having a cure for it
end -- found one
end -- for

end -- function do_cure


Note: When I copied it from my script file, the spacing messed up so it's all left alligned now.

Here's the error.


[string "Script file"]:6: <name> expected near `='


To the best of my knowledge (which I know in this subject is not very extensive), my script is pretty much exactly how you had it earlier, except with the changes specific to my file. Can you show me what I've done wrong?

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #34 on Sun 08 Jan 2006 10:27 PM (UTC)
Message
Well, line 6 (mentioned in the error message) is this, right?

Quote:

salvecures: = {


There is no colon. It should be:


salvecures = {


You can't just ignore errors and hope the script will work.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #35 on Mon 09 Jan 2006 02:10 AM (UTC)
Message
I'm having trouble with the whole trigger sending afflicted thing so I tried something else.

Trigger goes of and makes masochism = true


for _, v in ipairs (cures) do
if [v.name] = true then
if v.cure ~= "" then -- some afflictions might not have cures
Send ("outb ", v.cure) -- get out of bag
Send ("eat ", v.cure) -- eat it
ColourNote ("black", "yellow", "Curing " .. v.name ..
" with " .. v.cure)
eating = true
return -- done
end -- of having a cure for it
end -- found one
end -- for

end -- function do_cure


The only problem is that "if [v.name] = true then" gives me an error that says unexpected symbol near ]. Is there a help file on If statements so that I can see what I've done wrong?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #36 on Mon 09 Jan 2006 05:48 AM (UTC)
Message
The original line (which you had further up) was:


if afflicted_by [v.name] then


You have changed it to:


if [v.name] = true then


You have left out "afflicted_by", and also in an "if" test you should use "==" rather than "=".

The Lua manual, which is referenced in various places, describes the Lua syntax.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #37 on Thu 12 Jan 2006 01:08 AM (UTC)
Message
With the triggers that I have, it doesn't quite work.

[string "Trigger: "]:1: attempt to call global `afflicted' (a nil value)
stack traceback:
[string "Trigger: "]:1: in main chunk

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #38 on Thu 12 Jan 2006 05:37 AM (UTC)
Message
What is "afflicted"? The variable I had was "afflicted_by".

Note the different spelling and the underscore.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #39 on Fri 13 Jan 2006 12:45 AM (UTC)
Message
This is what you wrote on page 1.

<triggers>
<trigger
enabled="y"
match="You drive a clenched fist into your gut."
send_to="12"
sequence="100"
>
<send>afflicted "masochism"</send>
</trigger>
</triggers>


And I had wondered before if that was the problem so I changed it to what you afflicted_by just like you just said but it still gave me an error.

[string "Trigger: "]:1: attempt to call global `afflicted_by' (a table value)
stack traceback:
[string "Trigger: "]:1: in main chunk
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #40 on Fri 13 Jan 2006 03:47 AM (UTC)
Message
I am confused now as to what you have done to my original. In that I had this function:


-- call this from a trigger to show we are afflicted by something

function afflicted (what)
  if afflicted_by [what] then
    ColourNote ("white", "red", "Already afflicted by " .. what)
  else
    afflicted_by [what] = true  -- note the affliction
    ColourNote ("white", "red", "Now afflicted by " .. what)
  end -- if
  do_cure ()  -- try a cure
end -- function afflicted 


That is what the trigger is calling, the function "afflicted". In the syntax error you had you needed to use:


if afflicted_by [v.name] then


in your relevant piece of script.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #41 on Sun 15 Jan 2006 03:34 AM (UTC)
Message
Thanks! I pretty much have it all working except for one problem now. Part of my script has Send ("apply ", v.cure)
in it. That is fine, except that for 2 of my cures I have to "apply mending to legs" or "apply restoration to head". Do you have any idea how I could do that?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #42 on Sun 15 Jan 2006 11:12 PM (UTC)
Message
Can't you just make the cure "mending to legs"?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gid   (18 posts)  Bio
Date Reply #43 on Mon 16 Jan 2006 04:26 AM (UTC)
Message
Okay, so that works just fine now.

Just as a question beforehand, is there anyway I can have whatever my Send command sends to the world show in the output? I wanted to know this because now my triggers work, it gives me the messages that I am afflicted, that I am curing, but I don't think it send the right thing to to world because the world sends back the same messages as if I had just typed in "flkasdfgh" (meaning whatever my script is telling the world to do is just jibberish.
Send ("apply", v.cure) <-- this is from my script so I know that just just fine.


Another problem: People in the game can cast illusions to make me believe that my leg is broken, when it really is not. Also, one importan thing is that there are two different ways your arms can break, each requiring a different cure.

Here's what I would see:

Your arm breaks.
apply mending to arms <-- Called by the script, triggers won't respond to it I understand.
You take out some salve and quickly rub it on your arms.
You messily spread the salve over your body, to no effect.

Your arm breaks badly.
apply restoration to arms <--same as above
You take out some salve and quickly rub it on your arms.
You messily spread the salve over your body, to no effect.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #44 on Mon 16 Jan 2006 04:55 AM (UTC)
Message
Quote:

... is there anyway I can have whatever my Send command sends to the world show in the output?


It does. If you do: Send ("hello") it is echoed in the output window.

Quote:

... but I don't think it send the right thing to to world ...

Send ("apply", v.cure)


Assuming v.cure contains a word like "salve" it will send:


applysalve


You need a space after "apply", it won't put one in for you.

Quote:

Your arm breaks.

...

Your arm breaks badly.


What's the problem here? You make 2 triggers that match the different ways your arm can break.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


163,301 views.

This is page 3, subject is 5 pages long:  [Previous page]  1  2  3 4  5  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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