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


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, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ What does this mean?

What does this mean?

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


Pages: 1  2 3  

Posted by Katherina   (19 posts)  Bio
Date Reply #15 on Sun 27 Jan 2008 07:19 PM (UTC)
Message
Thank you to everyone who helped with this issue. It has been getting frustrating.
I optimized my code and turned timers off thinking it might have been the issue, but I still got the same type of error mid-battle needless to say I didn't win.

So basically it sounds like I have to convert all my code to lua script?

I've used mushclient for approx 7 years and I would prefer to keep it over going to another client.

Is lua much different from vbscript?
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #16 on Sun 27 Jan 2008 09:44 PM (UTC)
Message
Well, converting to Lua would certainly be an option, that might make things easier in the future. However what should solve your immediate problem with less work would be to move stuff from "send to script" to scripting functions inside a separate script file.

For more details about the differences between "send to script" and a script file, see:

htp://www.mushclient.com/scripting


Basically what would be involved is:


  • Make an empty script file in the text editor
  • Select that as the script file in the scripting configuration
  • For each trigger and alias, copy the "send to script" code from within it, and paste into a separate function in the script file, like this:

    
    Sub Trigger1 (name, line, wildcards)
    
    '  
    '  --> paste the script here
    '
    
    End Sub
    


  • Change the "send to" type from "send to script" back to "send to world". This stops it trying to compile it every time, and thus avoids the memory leak.

  • Put the name of the function (eg. Trigger1 in my example) in the "script" box of the trigger/aias.

  • If you used wildcards in the trigger/alias, you need to change them from %<something> to use the wildcards array. For example:

    Old
    
    nameofmob = "%1"
    



    New
    
    nameofmob = wildcards (1)
    


  • Save the script file (make sure it is reprocessed) and test it


If you want to convert to Lua instead, then you can leave things in "send to script". Lua is fairly similar in many ways to VBscript, but there are certainly differences. For one thing, Lua is case-sensitive, so where you got away with this in VBscript:


world.note "hi there"


In Lua that has to be:


world.Note "hi there"


If you are planning to convert to Lua it would help if you posted some examples (a couple of your more complex triggers perhaps) so I could look at your general style (that is, the things in VBscript that you usually use) and advise a way of quickly converting them.

- Nick Gammon

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

Posted by Katherina   (19 posts)  Bio
Date Reply #17 on Mon 28 Jan 2008 02:33 AM (UTC)
Message
Thank you I do appreciate the help. I play on Aetolia and the combat system is very complex, everyone has a 'system' for combat so I have to have one to keep up. Most do not use mushclient though and the ones who do that I have met aren't overly inclined to help.

I haven't done any real scripts, I have a background in programming but I graduated college as a Computer programmer 10 years ago, I'm just a little outdated. My strongest language is C/C++. It's been slowly coming back but the logic is still there.

I'll past the alias first, it's a simple one because the others are fairly large. The prompt which is similar to a "main" function I will post right after as the last time I was over the character limit to post.
I also do all the coding through the gui.

Alias:
CanAttack

if world.GetVariable ("erebound")=0 and world.getvariable ("hasshield")=0 then
world.Execute "ds"
end if
if world.getvariable ("erebound")=1 and world.getvariable ("hasshield")=1 then
world.Execute "rs"
end if
if world.getvariable ("erebound")=1 and world.getvariable ("hasshield")=0 then
world.Execute "rs"
end if
if world.getvariable ("erebound")=0 and world.getvariable ("hasshield")=1 then
world.Execute "rs"
end if
Top

Posted by Katherina   (19 posts)  Bio
Date Reply #18 on Mon 28 Jan 2008 02:36 AM (UTC)
Message
world.SetVariable "health", "%1"
world.SetVariable "mana", "%2"
dim curhp
dim curmp
curhp=%1
curmp=%2
if curhp < 2800 and world.GetVariable ("moss")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("anorexia")=0 then
world.Execute "emo"
world.SetVariable "moss", "0"
end if
if curhp < 3300 and world.GetVariable ("elixir")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("belonephobia")=0 and world.GetVariable ("addiction")=0 then
world.Execute "sh"
world.SetVariable "elixir", "0"
end if
if curmp < 2500 and curhp > 2900 and world.GetVariable ("elixir")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("belonephobia")=0 and world.GetVariable ("addiction")=0 then
world.Execute "sm"
world.SetVariable "elixir", "0"
end if
if world.GetVariable ("illusion")=1 then
world.Execute "resettemps"
end if
world.Execute "setaff"
if world.GetVariable ("indifference")=1 and world.GetVariable ("salve")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("slickness")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.Send "press oculi"
world.SetVariable "salve", "0"
end if
if world.GetVariable ("stupidity")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("illusion")=0 and world.GetVariable ("herb")=1 and world.GetVariable ("sleeping")=0 and world.GetVariable ("belonephobia")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("indifference")=0 and world.GetVariable ("stun")=0 then
world.Send "outc 2 liver slice"
world.Send "eat liver slice"
world.Send "inc liver slice"
end if
if world.GetVariable ("paralysis")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("illusion")=0 and world.GetVariable ("stupidity")=0 and world.GetVariable ("herb")=1 and world.GetVariable ("sleeping")=0 and world.GetVariable ("belonephobia")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("indifference")=0 and world.GetVariable ("stun")=0 then
world.Send "outc lung slice"
world.Send "eat lung slice"
world.SetVariable "herb", "0"
end if
if world.GetVariable ("limp_veins")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("balance")=1 and world.GetVariable ("aeon")=0 then
world.Send "Fitness"
world.SetVariable "balance", "0"
world.SetVariable "fitness", "1"
end if
if world.GetVariable ("slickness")=1 and world.GetVariable ("stun")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("limp_veins")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("illusion")=0 then
world.Execute "ia"
end if
if world.GetVariable ("belonephobia")=1 and world.GetVariable ("salve")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("slickness")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.Send "press oculi on torso"
setvariable "salve", "0"
end if
if world.GetVariable ("fsleep")=1 and world.GetVariable ("illusion")=0 and world.GetVariable ("sleeping")=1 and world.GetVariable ("aeon")=0 then
world.Execute "wake"
else
if world.GetVariable ("insomnia")=0 and getvariable ("fsleep")=0 and getvariable ("balance")=1 and getvariable ("equilibrium")=1 and getvariable ("sleeping")=0 and getvariable ("fighting")=1 then
world.Send "insomnia"
end if
end if
if getvariable ("limp_veins")=1 and getvariable ("slickness")=1 and getvariable ("belonephobia")=1 and getvariable ("paralysis")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 and world.GetVariable ("balance")=1 then
world.Send "fitness"
world.Execute "ia"
else
if getvariable ("limp_veins")=1 and getvariable ("slickness")=1 and getvariable ("belonephobia")=1 and getvariable ("paralysis")=1 and getvariable ("confusion")=1 and getvariable ("frozen")=1 then
world.SetVariable "truelock", "1"
end if
end if
if world.GetVariable ("broken_larm")=1 and world.GetVariable ("broken_rarm")=1 and world.GetVariable ("stun")=0 and world.GetVariable ("illusion")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("equilibrium")=1 then
world.Execute "restore"
end if
to be cont...
Top

Posted by Katherina   (19 posts)  Bio
Date Reply #19 on Mon 28 Jan 2008 02:36 AM (UTC)
Message
if world.GetVariable ("stun")=0 and world.GetVariable ("illusion")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("herb")=1 and world.GetVariable ("sleeping")=0 and world.GetVariable ("belonephobia")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("indifference")=0 then
world.SetVariable "ccslice", "1"
else
world.SetVariable "ccslice", "0"
end if
if world.GetVariable ("salve")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("slickness")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.SetVariable "ccpoultice", "1"
else
world.SetVariable "ccpoultice", "0"
end if
if world.GetVariable ("stun")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("moss")=1 and world.GetVariable ("sleeping")=0 and world.GetVariable ("anorexia")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.SetVariable "ccmoss", "1"
else
world.SetVariable "ccmoss", "0"
end if
if world.GetVariable ("stun")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("limp_veins")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("illusion")=0 then
world.SetVariable "ccsyringe", "1"
else
world.SetVariable "ccsyringe", "0"
end if
if world.GetVariable ("freedom")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("writhe")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("illusion")=0 then
world.Execute "CureWrithe"
end if
if world.GetVariable ("possessed")=1 and world.GetVariable ("stun")=0 and world.GetVariable ("frozen")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("balance")=1 and world.GetVariable ("sleeping")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.Send "lose soulmaster"
end if
if world.GetVariable ("stun")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("frozen")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("fear")=1 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.Send "Compose"
end if
if world.GetVariable ("prone")=1 and world.GetVariable ("stun")=0 and world.GetVariable ("dead")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("balance")=1 and world.GetVariable ("broken_lleg")=0 and world.GetVariable ("broken_rleg")=0 and world.GetVariable ("paralysis")=0 and world.GetVariable ("freedom")=1 and world.GetVariable ("illusion")=0 then
world.Send "stand"
end if
if world.GetVariable ("freedom")=1 and world.GetVariable ("dead")=0 and world.GetVariable ("stun")=0 and world.GetVariable ("writhe")=0 and world.GetVariable ("sleeping")=0 and world.GetVariable ("aeon")=0 and world.GetVariable ("illusion")=0 then
world.Execute "CureAll"
end if
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #20 on Mon 28 Jan 2008 04:15 AM (UTC)
Message
Ummm, Nick, the Lua conversion you posted was wrong, only slightly...

world.Note "hi there"

Should be...

world.Note("hi there")

I know it is a minor slip, but still for someone learning about Lua, they need all the finer details :)

-Onoitsu2
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #21 on Mon 28 Jan 2008 05:04 AM (UTC)
Message
Actually, the code I posted does work, try it and you will see. As a special case Lua allows a single string literal to appear with the brackets. Thus you can do this:


world.Note "hi there"


or


world.Note ("hi there")


I left the brackets out because it was closer to the VB syntax.

However if you want multiple things, or variables, you must use the brackets, eg.


world.Note ("two plus two = ", 2 + 2)


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #22 on Mon 28 Jan 2008 05:40 AM (UTC)

Amended on Mon 28 Jan 2008 05:51 AM (UTC) by Nick Gammon

Message
As for converting that script to Lua, this is what I did:


  1. Copied and pasted the whole thing into one of MUSHclient's notepad windows.

  2. I fixed the capitalization of function names, which Lua requires to be correct, by using the Search menu -> Global Replace (Ctrl+Shift+G), as described in the forum post "How to fix capitalization of function names in scripts":

    http://www.gammon.com.au/forum/?id=6211

    That is:

    
    
    Find Pattern: [%a%d]+
    Replacement: f
    Call function: checked
    Script:
    
    t1 = utils.functionlist ()
    t2 = {}
    
    -- keys are lower-case functions, values are original functions
    
    table.foreach (t1, function (k, v) t2 [string.lower (v)] = v end )
    
    function f (str)
      return t2 [string.lower (str)] or str
    end -- function f
    


    This changed things like world.getvariable to world.GetVariable

  3. I fixed up "if" statements by doing a global replace of "end if" to "end -- if"

  4. The word "world." is a bit redundant, so I changed "world." to nothing. So in other words:

    
    world.Execute "sh"
    


    becomes:

    
    Execute "sh"
    


  5. As Onoitsu2 pointed out, generally speaking Lua function calls have to be in brackets. In particular you were doing a lot of SetVariable without the brackets. So I used the Search menu -> Global Replace to do another big cleanup:

    
    Find Pattern: SetVariable%s*(.+)
    Replacement: SetVariable (%1)
    Call function: NOT checked
    


    This changes, for example:

    
    SetVariable "truelock", "1"
    


    to:

    
    SetVariable ("truelock", "1")
    


  6. To define local variables Lua uses "local" rather than "dim" so I changed:

    
    dim curhp
    dim curmp
    


    to

    
    local curhp
    local curmp
    


  7. Lua uses == to compare for equality, not =, so another fixup using Search menu -> Global Replace was required:

    
    Find Pattern: GetVariable%s*%(%s*(.-)%s*%)%s*=%s*(%d+)
    Replacement: GetVariable (%1) == "%2"
    Call function: NOT checked
    


    After running this lines like this:

    
    if world.GetVariable ("erebound")=0 and world.getvariable ("hasshield")=0 then
    


    changed to:

    
    if GetVariable ("erebound") == "0" and GetVariable ("hasshield") == "0" then
    


    Note also I quoted the number you are comparing to, as Lua considers "0" and 0 to be different. One is a string and one is a number.

  8. I wanted to make the long "if" statements a bit easier to read, so another Search menu -> Global Replace was used to break the long if statements after the "and", like this:

    
    Find Pattern:  and 
    Replacement:  and\n   
    Call function: NOT checked
    Escape sequences: checked
    


    The find pattern is actually: (space)and(space)
    The replace pattern is actually: (space)and\n(space)(space)(space)

    I mention that because the spaces are hard to see.

    This adds a line break after each "and".

  9. For neatness I also added a blank line after each if:

    
    Find Pattern: end %-%- if
    Replacement:  end -- if\n   
    Call function: NOT checked
    Escape sequences: checked
    


  10. I also wanted to indent the inside of an "if" like this:

    
    Find Pattern: ^Execute 
    Replacement:        Execute  
    Call function: NOT checked
    


    (That is 6 spaces before "Execute" in the replacement box).

    Ditto for the words "SetVariable" and "Send".


A couple of manual cleanups of spacing, and this is the finished result:


if GetVariable ("erebound") == "0" and
   GetVariable ("hasshield") == "0" then
      Execute "ds"
end -- if

if GetVariable ("erebound") == "1" and
   GetVariable ("hasshield") == "1" then
      Execute "rs"
end -- if

if GetVariable ("erebound") == "1" and
   GetVariable ("hasshield") == "0" then
      Execute "rs"
end -- if

if GetVariable ("erebound") == "0" and
   GetVariable ("hasshield") == "1" then
      Execute "rs"
end -- if


SetVariable ("health", "%1")
SetVariable ("mana", "%2")

local curhp
local curmp

curhp=%1
curmp=%2

if curhp < 2800 and
   GetVariable ("moss") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("anorexia") == "0" then
      Execute "emo"
      SetVariable ("moss", "0")
end -- if

if curhp < 3300 and
   GetVariable ("elixir") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("belonephobia") == "0" and
   GetVariable ("addiction") == "0" then
      Execute "sh"
      SetVariable ("elixir", "0")
end -- if

if curmp < 2500 and
   curhp > 2900 and
   GetVariable ("elixir") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("belonephobia") == "0" and
   GetVariable ("addiction") == "0" then
      Execute "sm"
      SetVariable ("elixir", "0")
end -- if

if GetVariable ("illusion") == "1" then
      Execute "resettemps"
end -- if

Execute "setaff"

if GetVariable ("indifference") == "1" and
   GetVariable ("salve") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("slickness") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Send "press oculi"
      SetVariable ("salve", "0")
end -- if

if GetVariable ("stupidity") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("illusion") == "0" and
   GetVariable ("herb") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("belonephobia") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("indifference") == "0" and
   GetVariable ("stun") == "0" then
      Send "outc 2 liver slice"
      Send "eat liver slice"
      Send "inc liver slice"
end -- if

if GetVariable ("paralysis") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("illusion") == "0" and
   GetVariable ("stupidity") == "0" and
   GetVariable ("herb") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("belonephobia") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("indifference") == "0" and
   GetVariable ("stun") == "0" then
      Send "outc lung slice"
      Send "eat lung slice"
      SetVariable ("herb", "0")
end -- if

if GetVariable ("limp_veins") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("balance") == "1" and
   GetVariable ("aeon") == "0" then
      Send "Fitness"
      SetVariable ("balance", "0")
      SetVariable ("fitness", "1")
end -- if

if GetVariable ("slickness") == "1" and
   GetVariable ("stun") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("limp_veins") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("illusion") == "0" then
      Execute "ia"
end -- if

if GetVariable ("belonephobia") == "1" and
   GetVariable ("salve") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("slickness") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Send "press oculi on torso"
      SetVariable ("salve", "0")
end -- if

if GetVariable ("fsleep") == "1" and
   GetVariable ("illusion") == "0" and
   GetVariable ("sleeping") == "1" and
   GetVariable ("aeon") == "0" then
      Execute "wake"
else
if GetVariable ("insomnia") == "0" and
   GetVariable ("fsleep") == "0" and
   GetVariable ("balance") == "1" and
   GetVariable ("equilibrium") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("fighting") == "1" then
      Send "insomnia"
end -- if

end -- if

if GetVariable ("limp_veins") == "1" and
   GetVariable ("slickness") == "1" and
   GetVariable ("belonephobia") == "1" and
   GetVariable ("paralysis") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" and
   GetVariable ("balance") == "1" then
      Send "fitness"
      Execute "ia"
else
if GetVariable ("limp_veins") == "1" and
   GetVariable ("slickness") == "1" and
   GetVariable ("belonephobia") == "1" and
   GetVariable ("paralysis") == "1" and
   GetVariable ("confusion") == "1" and
   GetVariable ("frozen") == "1" then
      SetVariable ("truelock", "1")
end -- if

end -- if

if GetVariable ("broken_larm") == "1" and
   GetVariable ("broken_rarm") == "1" and
   GetVariable ("stun") == "0" and
   GetVariable ("illusion") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("equilibrium") == "1" then
      Execute "restore"
end -- if


if GetVariable ("stun") == "0" and
   GetVariable ("illusion") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("herb") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("belonephobia") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("indifference") == "0" then
      SetVariable ("ccslice", "1")
else
      SetVariable ("ccslice", "0")
end -- if

if GetVariable ("salve") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("slickness") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      SetVariable ("ccpoultice", "1")
else
      SetVariable ("ccpoultice", "0")
end -- if

if GetVariable ("stun") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("moss") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("anorexia") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      SetVariable ("ccmoss", "1")
else
      SetVariable ("ccmoss", "0")
end -- if

if GetVariable ("stun") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("limp_veins") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("illusion") == "0" then
      SetVariable ("ccsyringe", "1")
else
      SetVariable ("ccsyringe", "0")
end -- if

if GetVariable ("freedom") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("writhe") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("illusion") == "0" then
      Execute "CureWrithe"
end -- if

if GetVariable ("possessed") == "1" and
   GetVariable ("stun") == "0" and
   GetVariable ("frozen") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("balance") == "1" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Send "lose soulmaster"
end -- if

if GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("frozen") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("fear") == "1" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Send "Compose"
end -- if

if GetVariable ("prone") == "1" and
   GetVariable ("stun") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("balance") == "1" and
   GetVariable ("broken_lleg") == "0" and
   GetVariable ("broken_rleg") == "0" and
   GetVariable ("paralysis") == "0" and
   GetVariable ("freedom") == "1" and
   GetVariable ("illusion") == "0" then
      Send "stand"
end -- if

if GetVariable ("freedom") == "1" and
   GetVariable ("dead") == "0" and
   GetVariable ("stun") == "0" and
   GetVariable ("writhe") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Execute "CureAll"
end -- if


I hope that gives the general flavour of the "before" and "after". If you have hundreds of similar aliases you could write a script that effectively automated those steps. If you only have a dozen it shouldn't take too long to do them by hand. You could copy and paste them all into one notepad file (separated by hyphens or something) and do each step on the lot as a batch.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #23 on Mon 28 Jan 2008 06:22 AM (UTC)
Message
What I mean by automating the process is ...

The Search menu -> Global Replace function in the internal notepad basically uses Lua string.gsub function to do its replacements. So you could do this:


  • Use the function GetAliasList to get a list of all the aliases.

  • For each alias, see if it uses "send to script"

  • If it uses "send to script" get a copy of the script (using GetAliasOption).

  • Run through the script doing each of the changes I mentioned, by using string.gsub. You may need a few other changes (eg. changing VB comments to Lua comments).

  • Put the corrected script back (SetAliasOption)

  • Move onto the next one


Ditto for triggers and timers.

I would certainly work on a copy of my world file, in case it doesn't work perfectly the first time.

- Nick Gammon

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

Posted by Katherina   (19 posts)  Bio
Date Reply #24 on Mon 28 Jan 2008 08:04 AM (UTC)
Message
Thank you so much for the time you have put into this. I really do appreciate it.

I've been going through and just pulling the code into word pad, doing replace all and double checking to make sure it's right. Won't that do the same thing?

I'm new to coding in any sort of mud client. I've used Mushclient for years but the other muds I played didn't allow triggers or scripts so never had to use it before. Lua is also completely new to me. I at least had some background with VB. Though it does look nearly the same and I understand the concepts.

Again thank you
Katherina
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #25 on Mon 28 Jan 2008 08:50 AM (UTC)
Message
Wordpad will certainly do some of the replacements, but some of the more sophisticated ones require something like the Global Replace. For example, the table lookup of lower-case function names to the correctly-capitalized one can be done in one pass in MUSHclient, but would require you to handle each one individually in Wordpad.

Also stuff like changing:

SetVariable "something", "something"

to

SetVariable ("something", "something")

is easier using the method I suggested because it is taking the somethings in the middle and putting brackets around them.

- Nick Gammon

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

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #26 on Mon 28 Jan 2008 05:48 PM (UTC)
Message
As useful as that conversion method would be for most people, I would only suggest using that to get started with Lua scripting. As you learn Lua, you can take advantage of many "tricks" Lua has within it, as well as taking advantage of the wonderful interface with MUSHclient (mostly due to not having to go through WSH).

When I first started using Lua, I went through and converted all of my VBscript and JScript plugins to Lua line by line. They worked alright, but once I actually learned what I was doing, I was able to completely rewrite all these files from scratch to be more elegant and efficient. It would be the same converting from Lua to VBscript or any other language. Each one has its own unique strong points.

The site that helped me out the most with learning Lua, and the one I still visit most frequently when I have questions, is on the Lua user wiki. This "tutorial" is not really a tutorial per se, but it does explain most of the functionality of Lua quite well.
http://lua-users.org/wiki/TutorialDirectory

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #27 on Mon 28 Jan 2008 09:22 PM (UTC)

Amended on Mon 28 Jan 2008 09:23 PM (UTC) by Nick Gammon

Message
True, you can make it more Lua-like, although initially I wanted it to look fairly much like VB to make it easier to make the transition. Here is something you could do ...

Instead of something like this, which does a lot of GetVariable:


if GetVariable ("stun") == "0" and
   GetVariable ("sleeping") == "0" and
   GetVariable ("frozen") == "0" and
   GetVariable ("dead") == "0" and
   GetVariable ("fear") == "1" and
   GetVariable ("aeon") == "0" and
   GetVariable ("illusion") == "0" then
      Send "Compose"
end -- if


You can write a helper function that gets the variable, and compares it to "1" (being "true" I presume). The function returns true if the variable is equal to "1" and false otherwise. Thus it could look shorter, like this:


function aff (which)
  return GetVariable (which) == "1"
end -- function aff

if not aff ("stun") and
   not aff ("sleeping") and
   not aff ("frozen") and
   not aff ("dead") and
   aff ("fear") and
   not aff ("aeon") and
   not aff ("illusion") then
      Send "Compose"
end -- if


I put "not" in front of the test if I wanted to be testing for false (that is, zero).

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #28 on Mon 28 Jan 2008 09:31 PM (UTC)
Message
You can get a bit fancier by making a table with a metatable which means you can have even less typing, along these lines:


aff = {}

setmetatable (aff, 
   {
   __index = function (t, name) 
              return GetVariable (name) == "1"
             end
   }
   )

if not aff.stun and
   not aff.sleeping and
   not aff.frozen and
   not aff.dead and
   aff.fear and
   not aff.aeon and
   not aff.illusion then
      Send "Compose"
end -- if



Notice now we have not needed to quote words like "stun".

You may want to read up on Lua table handling to see what is happening here, but basically we have an empty table called "aff" with a metatable on it that is called if a key (like "stun") is not found in the table. The metatable handler then does a GetVariable to return the appropriate result.

- Nick Gammon

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

Posted by Katherina   (19 posts)  Bio
Date Reply #29 on Mon 28 Jan 2008 11:00 PM (UTC)
Message
Awesome thank you both.
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.


92,415 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [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

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]