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
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
3
4 5
Posted by
| Gid
(18 posts) Bio
|
Date
| Reply #45 on Mon 16 Jan 2006 07:33 PM (UTC) |
Message
| The problem is that when I see this, my arms aren't really breaking, it is just an illusion. When I apply a salve and I don't have the affliction that I applied the salve for it gives me this message:
You messily spread the salve over your body, to no effect.
But I can't tell which salve I put on my body from that line. I want to be able to have the script recognize that this affliction is cured, but that line doesn't show me which salve I used so I can't tell it which affliction to say is cured.
I hope that made sense.... | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #46 on Mon 16 Jan 2006 09:51 PM (UTC) |
Message
| You would have to save that, when you apply a salve, in a variable as something like last_salve_applied.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gid
(18 posts) Bio
|
Date
| Reply #47 on Mon 16 Jan 2006 10:46 PM (UTC) |
Message
| I got it to log as a variable but I was wondering if this would work, and what the right syntax would be if it did.
function wasted_salve ()
if last_salve_applied = v.cure then
salvecured v.name
end -- function wasted_salve
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #48 on Mon 16 Jan 2006 10:51 PM (UTC) |
Message
|
Quote:
if last_salve_applied = v.cure then
salvecured v.name
That's 3 problems in 2 lines:
You really need to look closely at the syntax.
- To compare you use == not =
- To assign you use =
- You need "end" to end the if statement
So it should read:
if last_salve_applied == v.cure then
salvecured = v.name
end -- if
That's assuming I read your intentions correctly. :)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gid
(18 posts) Bio
|
Date
| Reply #49 on Tue 17 Jan 2006 12:05 AM (UTC) Amended on Tue 17 Jan 2006 01:22 AM (UTC) by Gid
|
Message
| Having some trouble....
<triggers>
<trigger
enabled="y"
group="Multi Line"
lines_to_match="2"
keep_evaluating="y"
match="You take out some salve and quickly rub it on your arms\.\nYou messily spread the salve over your body\, to no effect\.\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>wasted_salve</send>
</trigger>
</triggers>
function wasted_salve ()
if last_salve_applied == v.cure then
salvecured = v.name
end -- if
end -- function wasted_salve
[string "Trigger: "]:1: `=' expected near `<eof>' | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #50 on Tue 17 Jan 2006 04:31 AM (UTC) |
Message
| Read this page:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6030
You are combining two methods here. Either put wasted_salve into the "script" box of the trigger, and put your function into your script file, or have the command in the "send to script" without the function around it.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gid
(18 posts) Bio
|
Date
| Reply #51 on Thu 19 Jan 2006 02:40 AM (UTC) |
Message
| function wasted_salve ()
Note ("working")
if last_salve_applied == "v.cure" then
salveafflicted_by [what] = nil -- note not afflicted
ColourNote ("white", "green", "Now cured of " .. what)
do_salvecure () -- try a cure for the next affliction if any
end -- if
end -- function wasted_salve
function wasted_salve ()
Note ("working")
if last_salve_applied == "v.cure" then
salvecured "mending"
end -- if
end -- function wasted_salve
I've tried both of these. Neither bring back errors now but neither seem to work. When the trigger calls the function, the Note shows on the output but the If thing doesn't work. Just fyi the ColourNote also doesn't work on the first function. Do you see something that I don't?
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #52 on Thu 19 Jan 2006 03:39 AM (UTC) |
Message
|
Quote:
if last_salve_applied == "v.cure" then
You really need to think carefully about the difference between variables and literals.
Here you are saying "if the last salve was called 'v.cure' then do something".
I presume no salve is called 'v.cure'.
You want something like this:
if last_salve_applied == v.cure then
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Bobble
Canada (76 posts) Bio
|
Date
| Reply #53 on Wed 27 Dec 2006 12:21 AM (UTC) |
Message
| Greets all,
This is a bit of a thread resurrection, sorry about that.
I'm trying to teach myself lua scripting (I'm a sociology grad student by trade, so this isn't my area of expertise). As I was trying implement the bit of scripting Nick provided into my system for the IRE game I play, I ran into a little tidbit that I just couldn't wrap my mind around.
-- find an affliction we have, and try to cure it
function do_cure ()
-- can't eat more if just ate, or can't eat food
if eating or
afflicted_by.food or
afflicted_by.anorexia then
return
end -- if can't do it yet
-- find most urgent one to cure
etc. etc.
end -- function do_cure
The part in bold is throwing me off a bit. As I understand it, the "or" operator returns the first argument if it is not false and the second argument if the first is false. This is all fine and all, but I don't understand how it's behaving with the "if . . . then" control.
As I understand it, if . . . then statements operate off of a logical condition. If the condition is met, then the "then" action is carried out. If it is not met, then the "then" part won't be carried out. When I look at that bolded chunk, it seems to me that something is missing, shouldn't we be giving it some sort of logical condition like:
if eating = true then X
elseif afflicted_by.food then X
etc. (I come from a vbscript backgroud)
Why does simply returning the value of one of those three arguments (eating, afflicted_by.food, afflicted_by.anorexia) lead to the proper conditions for the "then" statement to be carried out.
(Looking back, that was a very verbose post, let me know if anything is unclear.) |
Open the watch. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #54 on Wed 27 Dec 2006 03:28 AM (UTC) |
Message
| "Or" is a boolean operator, which returns true if either of its arguments are true. In Lua, true is really any value other than nil or false.
Thus you could write:
if a or b or c or d or e then
-- do something
end
This would do the something inside the if statement, if any of those was true. Also in Lua (like other languages) the "or" is a short-circuit evaluation, thus it doesn't even bother to evaluate b (or c, d, or e) if a is true.
What it is really doing is evaluating "a or b" and then applying the result of that to c, and the result of that to d, ie. ((a or b) or c) or d.
The converse operation is "and" where you might write:
if a and b and c and d and e then
-- do something
end
Now the condition is only true if all of them are true. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Caelan
Vanuatu (12 posts) Bio
|
Date
| Reply #55 on Mon 05 Feb 2007 08:28 PM (UTC) |
Message
| Thread Necro is Good for the soul. That said, I had a question (rather than making a new thread, I'll be using examples from the first portion of this thread so I figured this is the place.)
This is to check for illusions since I haven't really found anything decent on "illusion" stuff about Achaea (some wait / pause things but not what I was looking for). In Achaea, the skill 'lifevision' can be used to detect illusions and gives a "** Illusion **" type msg if it detects one. As I am sure you know, this can come over the "illusion" or under it. What I wanted as a check to afflictions was this....:
I want to make the afflictions received enter a temporary table (basically a queue). Once I hit the new prompt, evaluate, see if it has tripped lifevision, if not, add it to the "afflicted_by" table as used in the beginning of this thread. If it has tripped lifevision, just wipe it out.
I was wondering if this idea pans out.
1. Make a "temp_afflicted" function similar to your "afflicted" function but assigns afflictions to the temp_table obviously.
2. Have another function to run on the prompt and see if lifevision was tripped or not and take the appropriate action (ie wiping temp_afflictions or adding it to "Afflicted_by" depending on the lifevision variable)
3. Once it adds it, it would have to reset the lifevision variable and the tem_afflicted table.
Would a function like this work for what I am trying to do?
lifevision = GetVariable("lifevision")
function temp_toreal ()
-- see if it picked up lifevision
if lifevision == 1 then
temp_afflicted [k] = nil
end -- if lifevision picked up
-- if lifevision didn't pick it up
for k in pairs (temp_afflicted) do
afflicted "[v.name]"
end -- for
end -- function
Just curious as this is my very first experience with MUSH, Lua, actual non-Zmud code, etc...So far I love it, but I am still unfamiliar with tables and what not thus far. Any help is appreciated and.. thanks ahead of time. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #56 on Mon 05 Feb 2007 09:38 PM (UTC) |
Message
| You need to be cautious with variable types here. The GetVariable function always returns a string (or nil if that variable doesn't exist).
Thus, comparing to 1 will always fail. For example:
a = "1"
print (a == 1) --> false
Assuming you are using "1" in lifevision to indicate "true", then you need this test:
if lifevision == "1" then ... blah blah
Also, I am a bit worried about this:
if lifevision == 1 then
temp_afflicted [k] = nil
end -- if lifevision picked up
-- if lifevision didn't pick it up
You are falling through here, is that intended? Perhaps you mean:
if lifevision == "1" then
temp_afflicted [k] = nil
return -- exit if found
end -- if lifevision picked up
-- if lifevision didn't pick it up
Although even then, I am unsure about your intentions. You are using "k" here, but "k" isn't defined yet. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Caelan
Vanuatu (12 posts) Bio
|
Date
| Reply #57 on Tue 06 Feb 2007 12:12 AM (UTC) |
Message
|
if lifevision == "1" then
temp_aff[k] = nil
return -- exit if found
for k in pairs (temp_aff) do
afflicted "[v.name]"
end -- for
end -- if
I have a table "temp_aff" to store what I MIGHT be afflicted with.
I have a table "afflicted_by" to store what I DO HAVE.
I want it so that if I see **Illusion** (@illusion) it just gets rid of the values in the temp_aff table until the next hit of afflictions.
If it doesn't say ** Illusion **, I want it to add whatever is currently in the 'temp_aff' table over to the 'afflicted_by' table.
From my limited understanding of tables, the first IF up there would say 'if it is in fact an illusion, and not really afflicting you, delete it from the temp_aff table'.
The second one, (again, to my understanding) says 'if it isn't an illusion, take all the keys stored in temp_aff (just names of afflictions so.... 'slickness', 'asthma', etc) and using the previous "afflicted" function, add that key to the actual "afflicted_by" table.
I am sure I am doing it wrong but, I am still new and a bit slow on the uptake. I hope I gave you enough info that time. I appreciate your help greatly, since I really like your product. | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #58 on Tue 06 Feb 2007 01:40 AM (UTC) |
Message
| Since I don't think Nick has much personal experience with Achaea, I believe I know what you're trying to do. Fixing your code, it would look something like:
Quote:
function temp_toreal ()
lifevision = GetVariable("lifevision")
-- see if it picked up lifevision
if (lifevision == '1') then
temp_afflicted = nil
return
end -- if lifevision picked up
-- if lifevision didn't pick it up
for k in pairs (temp_afflicted) do
afflicted(k)
end -- for
end -- function
this assumes that afflictions are stored in the index of temp_afflicted (temp_afflicted['asthma'] = true) not the value, and that there exists some function called afflicted, which takes as an argument a string of the affliction. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #59 on Tue 06 Feb 2007 04:24 AM (UTC) |
Message
|
Quote:
for k in pairs (temp_afflicted) do
If you set temp_afflicted to nil, then the next time you call this function the "pairs" will fail because it is being passed a nil argument. |
- 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,308 views.
This is page 4, subject is 5 pages long:
1
2
3
4 5
It is now over 60 days since the last post. This thread is closed.
Refresh page
top