denyCurrentSend

Post Reply
Swal
Posts: 14
Joined: Mon Mar 17, 2014 12:16 am

denyCurrentSend

Post by Swal »

Hi!

I'm working on a mapper for the mud I'm playing on, and denyCurrentSend and sysDataSendRequest plays a big role in it. Essentially what I'm doing is checking if I should be doing anything extra before sending the direction, if I have to, then I deny the send, send whatever I wanted before it, then resend the direction.
However I've started experiencing unexpected behavior.

I've managed to track down a bug that may be causing the issue I'm experiencing. The following, bare minimum script:

Have an alias/script sending to the server:
Code: [show] | [select all] lua
send("say replacethis")
have a script like this:
Code: [show] | [select all] lua
registerAnonymousEventHandler("sysDataSendRequest", "bugtest")
function bugtest(_, message)
	if message == "say replacethis" then
			denyCurrentSend()
			send("say replaced")
		return
	end
end
Means, I first deny the current send, then replace with a new. Right? No.


Outcome:
You say: replacethis

Expected:
You say: replaced

Now, if I switch two lines around, I get the expected behavior, but just looks broken to me:
Code: [show] | [select all] lua
registerAnonymousEventHandler("sysDataSendRequest", "bugtest")
function bugtest(_, message)
	if message == "say replacethis" then
			send("say replaced")
			denyCurrentSend()
		return
	end
end
Means I send the new text, then deny the current send... but isn't that the new current send, not the one I wanted to replace? I'm confused.

Note:
I used to have temp aliases for a similar purpose, but found this way of doing more expandable. One of the main drawback of that is I would have to create an alias for all possible way of entering a direction. Not to mention there are ways to skip alias pattern matching. sysDataSendRequest is more reliable.
Last edited by Swal on Tue Sep 09, 2014 1:27 am, edited 1 time in total.

Swal
Posts: 14
Joined: Mon Mar 17, 2014 12:16 am

Re: denyCurrentSend

Post by Swal »

Since then I have just decided to use denyCurrentSend as last code example shows. I'm surprised that everything works as I expect it to, but I have this feeling in the back of my mind that some random bug will pop up and will be traced back to this. Yet to test all scenario - like what if I need to replace it with more than 1 send -, so some unintended bug may still surface.

I have also found the following similar topic, my bad that I have not found it sooner: viewtopic.php?f=5&t=3519

I'm not sure what fix I even expect, because any would break everyone's existing script. Maybe an updated documentation regarding the expected use would be the best.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: denyCurrentSend

Post by Jor'Mox »

Yes, that is how you use denyCurrentSend, despite how confusing it may be. That said, wouldn't it just be simpler to make an alias that catches directions, and sends the extra commands along with the movement as necessary?

Swal
Posts: 14
Joined: Mon Mar 17, 2014 12:16 am

Re: denyCurrentSend

Post by Swal »

Alias would only work if the user actually entered the direction or if script sends it through expandAlias.
Also with aliases I would have to create all alias every single time I enter a new room with all possible way of entering each direction, then delete these aliases once I left the room.

The previous incarnation of my mapper used tempAliases, but they showed up as results when searching scripts, which annoyed me.

Also this way I can chain replacements*, while with alias it would be again more complicated, and I would heavily depend on all my script using expandAlias.

* Like:
Send left
replace left with: open door;left
then lets assume open door would get replaced with: insert key; turn key;open door
So the final list of items I send: insert key;turn key;open door;left

I believe similar would be harder to code with tempAliases, because I would have to create all aliases ahead and make sure I delete them when I don't need them instead of just looking up things to do only if they actually need to be done.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: denyCurrentSend

Post by Jor'Mox »

Or, you could make a single alias that captured all possible directions/exits instead if creating and deleting on the fly (which would be slow). It would be dependent on using expandAlias as opposed to send, but otherwise it would be identical in terms of processing needed, and it would likely be a bit simpler in terms of keeping things happening in the order you want them to happen. Either way, if what you have works, then there is no reason not to go that route, it just seems to be potentially more problematic.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: denyCurrentSend

Post by Vadi »

I think you want to put your send on a tempTimer(0, ...). denyCurrentSend() blocks the current set of sending stuff, so to speak.

Also yay, another mapper script.

Post Reply