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.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Inquiry on auto perform/cast script

Inquiry on auto perform/cast script

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


Posted by Hidelensman   (10 posts)  Bio
Date Fri 25 Aug 2023 12:52 PM (UTC)

Amended on Fri 25 Aug 2023 01:44 PM (UTC) by Hidelensman

Message
Hi Nick and all,

Thanks for your previous advice on the scripting and I'm playing the MUD much better than 20 years ago (yes the same MUD I played when I was a child lol)

Recently I found some old Lua code and want to revise it for my char, while it cannot work so want to consult you:


  • Goal: auto perform/cast when enter a fight
  • If the 1st attempt fails, then auto perform/cast again until succeeds
  • Multiple criteria of failure and success


The following are my codes and appreciate your help to advise where goes wrong:

New self-defined function 1: if ts/tw matched, return true; if fs/fw matched, return false
function mywait(ts, fs, tw, fw)
	local expr = "^(" .. table.concat(ts, "|") .. "|" .. table.concat(fs, "|") .. ")$"
	local l, w = wait.regexp(expr)
	if not l then return false end
	if tw then
		for _, v in pairs(tw) do
			if string.find(l, v) then return true end
		end
	end
	if fw then
		for _, v in pairs(fw) do
			if string.find(l, v) then return false end
		end
	end
	for _, v in pairs(fs) do
		if string.find(l, v) then return false end
	end
	for _, v in pairs(ts) do
		if string.find(l, v) then return true end
	end
	return true
end


New self-defined function 2

function myrepeat(cmd, ts, fs, tw, fw, t)
	repeat
		Execute(cmd)
		local rpt = mywait(ts, fs, tw, fw)
		if rpt and t then
			wait.time(t)
		end
	until not rpt
end


New Mushclient variable "pfm": pfm boundary

Auto perform script: same for auto_cast


function auto_pfm()
	local p = "p"
	if var.pfm and var.pfm ~= "" then p = var.pfm end
	myrepeat(p, {"xxx1", "xxx2"}, {"yyy1", "yyy2", "yyy3", "yyy4"}, nil, nil, 0.5)
	if f then f() end
end


Note

  • xxx1, xxx2: criteria of failed perform (i.e. the auto perform script should continue executing if "xxx1" and "xxx2" appear)
  • yyy1, yyy2, yyy3, yyy4: criteria of successful perform (i.e. the auto perform script should stop if "yyy1~4" appear)
  • xxx1, xxx2, yyy1, yyy2, yyy3, yyy4 are in traditional Chinese (with regular expression) so I don't put the original words here, while I tested them via regex101 as well as new Muchclient triggers and both methods work fine



After trial and errors for 2 weeks, I still cannot make the script work as what I expect so would like to seek for your opinion to improve them. Thanks.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 26 Aug 2023 05:19 AM (UTC)
Message
It's hard to say without more context. Is this all in an alias? Or what? Do you use the "wait" module? We can't test or reproduce with snippets like this.

Your use of tiny variable names isn't helping. This sort of stuff doesn't tell us what you are trying to do:

Quote:

function mywait(ts, fs, tw, fw)
...
function auto_pfm()
local p = "p"
if var.pfm and var.pfm ~= "" then p = var.pfm end
myrepeat(p, {"xxx1", "xxx2"}, {"yyy1", "yyy2", "yyy3", "yyy4"}, nil, nil, 0.5)


It looks somewhat like line noise.

There is no benefit from using small variable names. Lua is pre-compiled before it is executed (into bytecode). Using small variable names doesn't make it any faster, it is just confusing for everyone including, I dare say, yourself.

- Nick Gammon

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

Posted by Hidelensman   (10 posts)  Bio
Date Reply #2 on Sat 26 Aug 2023 08:02 AM (UTC)

Amended on Sun 27 Aug 2023 11:35 AM (UTC) by Hidelensman

Message
Nick Gammon said:

It's hard to say without more context. Is this all in an alias? Or what? Do you use the "wait" module? We can't test or reproduce with snippets like this.

Your use of tiny variable names isn't helping. This sort of stuff doesn't tell us what you are trying to do:


Thanks Nick - sorry some info might be lost when I typed the post.

Yes I already require "wait" in the game so don't specifically call "wait" module in these self-defined functions again.

I use these scripts when enter into a fight: when encountering a mob, call "auto_pfm()", and intend to continuously execute the command included in "auto_pfm()" until the stop criteria matched.

Nick Gammon said:

It looks somewhat like line noise.

There is no benefit from using small variable names. Lua is pre-compiled before it is executed (into bytecode). Using small variable names doesn't make it any faster, it is just confusing for everyone including, I dare say, yourself.


In fact the xxx1, xxx2, yyy1, yyy2, yyy3, yyy4 are not variables - they are the criteria to continue or stop the auto perform, while because they are in Chinese so I didn't paste the words here.

Admittedly the idea/original codes are from a post in another forum (posted about 10 years ago) - I think they can fulfill my need so try to adjust for my purpose.

Any good suggestion on how to debug or revise my codes? Or any advice on how to create an auto perform script for fighting? Thanks.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 27 Aug 2023 06:13 AM (UTC)
Message
Hidelensman said:

In fact the xxx1, xxx2, yyy1, yyy2, yyy3, yyy4 are not variables - they are the criteria to continue or stop the auto perform, while because they are in Chinese so I didn't paste the words here.



I was thinking more of these variables:


 function mywait(ts, fs, tw, fw)


ts, fs, tw, fw?

What the heck?

Hidelensman said:

Admittedly the idea/original codes are from a post in another forum ...


OK, so this isn't your code, so you aren't sure what it does. That makes two of us.

We can't help you if we can't reproduce the problem. You need to provide a minimal example that actually demonstrates the issue.

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


We can't debug code, written by someone else, provided in snippets and not in context, without any test data.

You need to show:


  • The actual triggers/aliases/timers you are using for this activity
  • The output from the MUD that is supposed to make things happen
  • What actually happens
  • What you expect to happen

- 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.


3,818 views.

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.