Problem again with Logging

Posted by Markomo on Sun 06 Oct 2024 10:32 PM — 18 posts, 29,960 views.

#0
Hello there I am again :)

I hope you can help me. I am using this alias to do research in Mud. Of course there are objects that don't exist because there is no description.

So when I run the alias I get the feedback “XY nicht gefunden.”

Now, if this happens, I want the alias not to save this in the log.


<aliases>
  <alias
   match="^b ([A-z]+)$"
   enabled="y"
   group="Forschen"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetLogInput (true)
vitem = "%1"
LogSend("untersuche "..vitem)
LogSend("lausche "..vitem)
LogSend("rieche "..vitem)
LogSend("beruehre "..vitem)
LogSend("fuehle "..vitem)
FlushLog()
</send>
  </alias>
</aliases>


Now I have customized the alias.


<aliases>
  <alias
   match="^b ([A-z]+)$"
   enabled="y"
   group="Forschen"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>    
    vitem = "%1"
    SendNoEcho("untersuche "..vitem)  
    SendNoEcho("lausche "..vitem)
    SendNoEcho("rieche "..vitem)
    SendNoEcho("beruehre "..vitem)
    SendNoEcho("fuehle "..vitem)


    function CheckResult(result)
      if not string.find(result, "nicht gefunden") then
        SetLogInput(true)
        LogSend("untersuche "..vitem)
        LogSend("lausche "..vitem)
        LogSend("rieche "..vitem)
        LogSend("beruehre "..vitem)
        LogSend("fuehle "..vitem)
        FlushLog()
      end
    end
    GetResponse("CheckResult")</send>
  </alias>
</aliases>


But unfortunately Mushclient tells me this error.


[string "Alias: "]:22: attempt to call global 'GetResponse' (a nil value)
stack traceback:
	[string "Alias: "]:22: in main chunk


Does anyone have any other ideas?

Thanks!

/edit: Ah, that's because the GetResponse function does not exist in the MUSHclient. The MUSHclient does not have a built-in system to wait directly for the server response and process it before taking any further action. Right?
Amended on Mon 07 Oct 2024 09:29 AM by Nick Gammon
Australia Forum Administrator #1
Yes. Did ChatGPT write that? It tends to make up functions it hopes exists.

Read this: http://www.gammon.com.au/forum/?id=4957

It shows how you can send something and wait for a response.
#2
Nick Gammon said:

Yes. Did ChatGPT write that? It tends to make up functions it hopes exists.

Read this: http://www.gammon.com.au/forum/?id=4957

It shows how you can send something and wait for a response.


Hello Nick!

First of all, thank you for answering me. No, I did not use ChatGPT. I had several browser tabs open at the time and used the wrong function.

I didn't even know that I could ask ChatGPT about it. Good to know, but I don't think an AI can help me here. That's where I need you! :)

But if I look at your link, I don't think I can implement the whole thing. My experience in Lua/Scripting is very basic.

Too bad. Thank you anyway.

BR
Australia Forum Administrator #3
Simple example from that page:


require "wait"

wait.make (function ()  --- coroutine below here

  repeat
    Send "cast heal"
    line, wildcards = 
       wait.regexp ("^(You heal .*|You lose your concentration)$", 10)

  until line and string.match (line, "heal")

  -- wait a second for luck
  wait.time (1) 

  Note ("heal done!")

end)  -- end of coroutine

Australia Forum Administrator #4
OK, so you are basically sending "investigate XY" and you possibly might get the response "XY not found" or "XY (something else)".

So you could do what I posted above and send "investigate XY" and then wait for a line starting with "XY" and if it isn't followed by "not found" then log it and then do your next research, namely "listen XY" and so on.

Something like that. :)
#5
Nick Gammon said:

OK, so you are basically sending "investigate XY" and you possibly might get the response "XY not found" or "XY (something else)".

So you could do what I posted above and send "investigate XY" and then wait for a line starting with "XY" and if it isn't followed by "not found" then log it and then do your next research, namely "listen XY" and so on.

Something like that. :)


That is correct. I send the alias “b boden” and get this output back:

b boden
untersuche boden
lausche boden
rieche boden
beruehre boden
fuehle boden

Text from untersuche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from lausche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from rieche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from berühre
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from fühle
202/202AP 213/213PE 113EP 12:44> my Prompt

My current alias now saves the echo of my alias:

b boden
untersuche boden
lausche boden
rieche boden
beruehre boden
fuehle boden

It works perfectly! What I want now is. If I type in “b xdxdxd” I get

b xdxdxd
untersuche xdxdxd
lausche xdxdxd
rieche xdxdxd
beruehre xdxdxd
fuehle xdxdxd

Xdxdxd nicht gefunden. (it means in german "Xdxdxd not found."
202/202AP 213/213PE 115EP 13:00> my promot
Xdxdxd nicht gefunden.
202/202AP 213/213PE 115EP 13:00>
Xdxdxd nicht gefunden.
202/202AP 213/213PE 115EP 13:00>
Xdxdxd nicht gefunden.
202/202AP 213/213PE 115EP 13:00>
Xdxdxd nicht gefunden.
202/202AP 213/213PE 115EP 13:00>

That the echo (Commandecho/Inputecho?) I mean this:

b xdxdxd
untersuche xdxdxd
lausche xdxdxd
rieche xdxdxd
beruehre xdxdxd
fuehle xdxdxd

should not be saved in the log file. This is currently happening. It always saves the command output

I suspect that I need some kind of logic to check this and my skills are not sufficient for that.
Amended on Mon 07 Oct 2024 11:08 AM by Markomo
Australia Forum Administrator #6
What do you see if the item *is* found?
#7
Nick Gammon said:

What do you see if the item *is* found?


Whatever the mud answers me. I will gladly describe it in English.

Player -> look floor
Mushclient Input Echo -> look flor
OutputMud ->The floor looks nice.

and if you haven't found something, the mud will tell you.

look wall
wall not found.

And I would like that when I get a result from mud like “look floor” that my command “look floor” is saved in the logfile.

But currently it also saves “look wall” and that's exactly what I don't want.
Amended on Tue 08 Oct 2024 12:36 AM by Markomo
Australia Forum Administrator #8
Well, the simple approach is to make a trigger that omits "not found" from the log file, like this:


<triggers>
  <trigger
   enabled="y"
   match="* nicht gefunden."
   omit_from_log="y"
   sequence="100"
  >
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


That way, if you are logging, and something is not found, it just won't log that line.

You might conceivably also omit the prompt, as that would just clog up the log file.
#9
Nick Gammon said:

Well, the simple approach is to make a trigger that omits "not found" from the log file, like this:


<triggers>
  <trigger
   enabled="y"
   match="* nicht gefunden."
   omit_from_log="y"
   sequence="100"
  >
  </trigger>
</triggers>


(pasting)

That way, if you are logging, and something is not found, it just won't log that line.

You might conceivably also omit the prompt, as that would just clog up the log file.


I want to save my alias commands echo and not the output from the mud in the log file. Currently it saves every command/echo from my alias.

But if the alias finds an item that contains “not found.”... I don't want the alias command to be saved.
#10
hello nick.

I see that you don't have a solution to my problem either.

i still wanted to thank you for your time :)

thank you very much!
Australia Forum Administrator #11
Quote:

look wall
wall not found.

...

But currently it also saves “look wall” and that's exactly what I don't want.


Your problem here is that you have already logged "look wall" before you find out that there is no wall there. So you have to rethink your approach.

For example, rather than have the client log your commands you could save them into a variable. Then when you get a response, other than "not found" then you manually log the command. See:

Template:function=WriteLog
WriteLog

The documentation for the WriteLog script function is available online. It is also in the MUSHclient help file.

#12
Nick Gammon said:

Quote:

look wall
wall not found.

...

But currently it also saves “look wall” and that's exactly what I don't want.


Your problem here is that you have already logged "look wall" before you find out that there is no wall there. So you have to rethink your approach.

For example, rather than have the client log your commands you could save them into a variable. Then when you get a response, other than "not found" then you manually log the command. See:

(function=WriteLog)


thanks again nick. but that's exactly where i get stuck. that's where i would have needed your help.

I just don't have a clue.

--------------

i ask chatgpt (thanks for this information @nick). what do you think about it?

<aliases>
<alias
match="^b ([A-z]+)$"
enabled="y"
group="Forschen"
regexp="y"
send_to="12"
sequence="100"
>
<send>
local message = GetLineInfo(1)
local vitem = "%1"
if not string.find(message, "%w+ nicht gefunden") then
commands = {
"untersuche "..vitem,
"lausche "..vitem,
"rieche "..vitem,
"beruehre "..vitem,
"fuehle "..vitem
}

for _, cmd in ipairs(commands) do
LogSend(cmd)
end

FlushLog()
else
Note("Text mit 'nicht gefunden' erkannt. Befehle werden nicht ausgeführt.")
end
</send>
</alias>
</aliases>


-------------

another approach would be this

<aliases>
<alias
match="^b ([A-z]+)$"
enabled="y"
group="Forschen"
regexp="y"
send_to="12"
sequence="100"
>
<send>
local vitem = "%1"
commands = {
"untersuche "..vitem,
"lausche "..vitem,
"rieche "..vitem,
"beruehre "..vitem,
"fuehle "..vitem
}

local all_commands = table.concat(commands, "\n")

if not string.find(all_commands, "nicht gefunden.") then

for _, cmd in ipairs(commands) do
LogSend(cmd)
end

FlushLog()
else
Note("A command with 'nicht gefunden.' detected.")
end
</send>
</alias>
</aliases>
Amended on Thu 10 Oct 2024 05:50 AM by Markomo
Australia Forum Administrator #13
ChatGPT can get things right. In this case it has ignored what I suggested. To help you further I need to see exactly what you see when you run your alias. I am guessing you don't see "my prompt" or "Text from lausche".

From your earlier post:


Text from untersuche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from lausche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from rieche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from berühre
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from fühle
202/202AP 213/213PE 113EP 12:44> my Prompt



Copy and paste the exact MUD output from a successful attempt and an unsuccessful one.
#14
Nick Gammon said:

ChatGPT can get things right. In this case it has ignored what I suggested. To help you further I need to see exactly what you see when you run your alias. I am guessing you don't see "my prompt" or "Text from lausche".

From your earlier post:


Text from untersuche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from lausche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from rieche
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from berühre
202/202AP 213/213PE 113EP 12:44> my Prompt
Text from fühle
202/202AP 213/213PE 113EP 12:44> my Prompt



Copy and paste the exact MUD output from a successful attempt and an unsuccessful one.


i use this alias atm:

--------------------
<aliases>
<alias
match="^b ([A-z]+)$"
enabled="y"
group="Forschen"
regexp="y"
send_to="12"
sequence="100"
>
<send>vitem = "%1"
LogSend("untersuche "..vitem)
LogSend("lausche "..vitem)
LogSend("rieche "..vitem)
LogSend("beruehre "..vitem)
LogSend("fuehle "..vitem)
FlushLog()</send>
</alias>
</aliases>
-----------

i'll take a screenshot for you. i think that will help you the most.

https://ibb.co/Ldm9J7K (imagehoster)

as you can see, i execute the alias twice. yellow = it has found an object. this is also saved with the current alias.

then i run the alias again. it doesn't find the object and outputs “Xdxdxd not found.” for the alias, of course, it looks as if something has been found, because i get an output from mud. i want the alias not to save this in the logfile (see right side). but it currently does.
Amended on Thu 10 Oct 2024 06:43 AM by Markomo
Australia Forum Administrator #15
I still think the simplest thing is to do WriteLog to say what you are examining and then use the trigger with omit from log to throw away lines which say "not found".
#16
Nick Gammon said:

I still think the simplest thing is to do WriteLog to say what you are examining and then use the trigger with omit from log to throw away lines which say "not found".


do you have an approach for me on how to change the alias?

you said to save the output in a variable first and then check it?
#17
Nick Gammon said:

I still think the simplest thing is to do WriteLog to say what you are examining and then use the trigger with omit from log to throw away lines which say "not found".


hey nick,

i now have the following alias. the alias does not saves the echo from the alias in the logfile. do you have any further input for me?

<aliases>
<alias
match="^b ([A-z]+)$"
enabled="y"
group="Forschen"
regexp="y"
send_to="12"
sequence="100"
>
<send>
vitem = "%1"
commands = {}
table.insert(commands, "untersuche " .. vitem)
table.insert(commands, "lausche " .. vitem)
table.insert(commands, "rieche " .. vitem)
table.insert(commands, "beruehre " .. vitem)
table.insert(commands, "fuehle " .. vitem)

for i, cmd in ipairs(commands) do
Send(cmd)
end
</send>
</alias>
</aliases>

/edit: i have found a solution for my problem and thank you for your help.