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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  New to MUSHclient

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: New to MUSHclient
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1  2  3 4  5  

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Fri 16 Feb 2007 01:18 PM (UTC)  quote  ]

Amended on Fri 16 Feb 2007 01:24 PM (UTC) by Caelan

Message
I got it to work. Thanks for the help.

I use tempafflicted to work the same as your 'afflicted' table function from before... then the other function is like this...


function tempafflicted (what)
  temp_aff 
Template:what Please help us by showing:
  • A copy of the trigger, alias or timer you were using (see Copying XML)
  • The error message, if any, that you got
= true -- note the affliction end -- function afflicted function temp_toreal () -- see if it picked up lifevision if GetVariable ("lifevision") == "1" then temp_aff = {} return end -- if for k in pairs (temp_aff) do afflicted (k) end -- for temp_aff = {} SetVariable ("lifevision", 0) end -- function


Anytime it picks up '** Illusion **' it just clears any afflictions so the '** Illusion **' could have come before or after the msgs (but before the prompt as it always does).

Thanks again.

Edit : I got the idea here -
http://www.gammon.com.au/forum/bbshowpost.php?id=6670
but I think this is way easier (at least for me) when combined with the info at the beginning of this thread. I was able to set up a healing setup that goes off all the seperate balances (tree/focus/herb/salve/smoke (no balance on smoking though but for aeon it would be helpful)) and doesn't trip up so long as the person has lifevision. Now I just need to further illusion-proof for times when lifevision doesn't pick up the Illusion. THANKS A TON!
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 06 Feb 2007 06:42 PM (UTC)  quote  ]
Message
Quote:

lifevision = GetVariable("lifevision")
-- see if it picked up lifevision

if (lifevision == true) then


You haven't addressed here my concerns expressed earlier about variable types. You are using "true" here which is a boolean type, but GetVariable returns a string type. These are two different data types, and thus the expression " (lifevision == true)" will always be false. That is, it will never execute the code inside that 'if".

I suggest you play around with Lua a bit to get a feel for the syntax, perhaps a simple program in the Immediate window to print a list of numbers and multiply them by 2, something like that. Then you will feel more comfortable tackling more complex problems.

Quote:

The assumption is that temp_afflicted is created somewhere else in the script, and that this is appropriately checked.


It is my experience that it is usually assumptions that bring programs undone.

The code below should be syntactically correct, whether it works or not depends on what the variables are used for elsewhere:



function temp_toreal ()

-- see if it picked up lifevision

 if GetVariable ("lifevision") == "1" then
  temp_aff = {}
  return
 end -- if

  for k in pairs (temp_aff) do
   afflicted (k)
  end -- for

end -- function

- Nick Gammon

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

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Tue 06 Feb 2007 03:41 PM (UTC)  quote  ]
Message
The idea is right, but there are a couple syntax problems.


if (lifevision == true) then
  temp_aff = {}
  return
 end


the 'end' right there closes the if statement. This means that you can't continue it with the elseif. Because of the return statement, you can eliminate the elseif altogether. If the script execution gets to that point, it is guarenteed lifevision is false; if not, it would have returned from the function.
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Tue 06 Feb 2007 11:51 AM (UTC)  quote  ]
Message
So would this work since it depends on the IF?

function temp_toreal ()
lifevision = GetVariable("lifevision")
-- see if it picked up lifevision

 if (lifevision == true) then
  temp_aff = {}
  return
 end -- if

 elseif (lifevision == false)
  for k in pairs (temp_aff) do
   afflicted(k)
  end -- for
 end -- if
end -- function


temp_aff is the table. temp_afflicted would be a function similar to the previous 'afflicted' one to assign the afflictions to the temp_aff table. If lifevision is true, I want all afflictions (would be 2 or 3 tops) cleared out of the temp_aff table.
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Tue 06 Feb 2007 05:09 AM (UTC)  quote  ]
Message
The assumption is that temp_afflicted is created somewhere else in the script, and that this is appropriately checked. You could equally set it equal to {} instead of nil.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 06 Feb 2007 04:24 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Tue 06 Feb 2007 01:40 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Tue 06 Feb 2007 12:12 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 05 Feb 2007 09:38 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Caelan   Vanuatu  (12 posts)  [Biography] bio
Date Mon 05 Feb 2007 08:28 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 27 Dec 2006 03:28 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Bobble   Canada  (76 posts)  [Biography] bio
Date Wed 27 Dec 2006 12:21 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 19 Jan 2006 03:39 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Gid   (18 posts)  [Biography] bio
Date Thu 19 Jan 2006 02:40 AM (UTC)  quote  ]
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?
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 17 Jan 2006 04:31 AM (UTC)  quote  ]
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
[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.


19,790 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]