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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  Jscript & mushclient arrays
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Jscript & mushclient arrays

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


Posted by Prattler   Lithuania  (15 posts)  [Biography] bio
Date Wed 11 Jan 2006 07:20 PM (UTC)

Amended on Wed 11 Jan 2006 07:21 PM (UTC) by Prattler

Message
I'm desperate.. I believe this is a bug and a very strange one.. :(

Code:
---
ArraySet("player_records", wildcards[0], ArrayExport("temp_player_record", ","));

note (ArrayGet("player_records", wildcards[0]));

// this should be the same command but lagged
DoAfterSpecial(0.1, "note (ArrayGet(\"player_records\", \"" + wildcards[0] + "\"))", 12);
---

Here is what I get:
1136752032844,lvl\,968\,qp\,56373\,gq\,14\,cp\,466,1137009997339,lvl\,1003\,qp\,57773\,gq\,14\,cp\,480
1136752032844,lvl\,968\,qp\,56373\,gq\,14\,cp\,466,1137009997339,lvl\,1003\,qp\,57773\,gq\,14\,dp\,480
(these should be identical, but notice the c and d at the end of those lines)

1136757632175,lvl\,707\,qp\,42422\,gq\,4\,cp\,220,1137010191078,lvl\,707\,qp\,42439\,gq\,4\,cp\,220
1136757632175,lvl\,707\,qp\,42422\,gq\,4\,cp\,220,1137010191078,lvl\,707\,qp\,42439\,gq\,4\,cp\-220
(now the "," and "-")

And so on. Seems that at exactly that place the charcode increases by one. How can this be? How can they differ at all? From what I've tested it's not a problem with the note function. Something with memory/the way arrays work?

Confused Pratter
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 12 Jan 2006 05:35 AM (UTC)
Message
It would help to know what wildcards [0] is, but it seems to be you are doing different things here.

Let's say wildcards [0] is "abc".

Now your first line is:


var key = "abc";
note (ArrayGet("player_records", key));


Your second line is:


note (ArrayGet("player_records", "abc"));


You may say these are the same, but what if there are funny characters in the key? Like quote symbols, or backslashes? Then the two methods will behave differently.


- Nick Gammon

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

Posted by Prattler   Lithuania  (15 posts)  [Biography] bio
Date Reply #2 on Thu 12 Jan 2006 08:08 PM (UTC)

Amended on Thu 12 Jan 2006 08:14 PM (UTC) by Prattler

Message
After about 5 hours of trying to duplicate it.. I THINK I might have something.. It's a lot of reading, but please spare some time.

-----------------------------------------
function doTesting() {
AddTrigger("testing_trigger", "test", "",
eTriggerRegularExpression + eEnabled + eReplace + eTemporary,
NOCHANGE, 0, "", "triggerFired");

// need something to fire the trigger, the mud supports echo, but it can be anything
world.Send("echo test");
}

function triggerFired() {
var date = new Date();
var time = date.getTime();

ArrayCreate("large_array");

ArrayCreate("small_array");
ArrayClear("small_array");

ArrayImport("small_array", ArrayGet("large_array", "same_key"), ",");

var line = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
ArraySet("small_array", time, line);

ArraySet("large_array", "same_key", ArrayExport("small_array", ","));

note(ArrayGet("large_array", "same_key"));
DoAfterSpecial(0.1,"note (ArrayGet(\"large_array\", \"same_key\"))",12);
}
-----------------------------------------

I fire doTesting() twice and I get exactly what I want:
test
1137099506087,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1137099506087,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

test
1137099506087,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,1137099509121,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1137099506087,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,1137099509121,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

now the fun part.. we change the script by adding
DeleteTrigger("testing_trigger");
in the second function. Everything else is left the same:
-----------------------------------------
function doTesting() {
AddTrigger("testing_trigger", "test", "",
eTriggerRegularExpression + eEnabled + eReplace + eTemporary,
NOCHANGE, 0, "", "triggerFired");

// need something to fire the trigger, the mud supports echo, but it can be anything
world.Send("echo test");
}

function triggerFired() {
var date = new Date();
var time = date.getTime();

DeleteTrigger("testing_trigger");

ArrayCreate("large_array");

ArrayCreate("small_array");
ArrayClear("small_array");

ArrayImport("small_array", ArrayGet("large_array", "same_key"), ",");

var line = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
ArraySet("small_array", time, line);

ArraySet("large_array", "same_key", ArrayExport("small_array", ","));

note(ArrayGet("large_array", "same_key"));
DoAfterSpecial(0.1,"note (ArrayGet(\"large_array\", \"same_key\"))",12);
}
-----------------------------------------

I clear the value by ArraySet("large_array", "same_key", "")
run doTesting() twice again.

Now I get:
test
1137099525825,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1137099525825,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

test
1137099525825,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,1137099526646,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1137099525825,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,1137099526646,aaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaa

Notice the b almost at the end of the second line. Please please tell me something is wrong here.. Deleting the trigger shouldn't do anything!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 13 Jan 2006 03:04 AM (UTC)
Message
I'm looking into it. When I did your test I got MUSHclient to crash. You seem to be onto something here, not sure what it is yet.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 13 Jan 2006 03:26 AM (UTC)
Message
My initial reaction here, is that you should not delete a trigger that is in the middle of executing a script. That is, do not delete yourself. This is generally bad programming practice.

I'm not certain whether or not this is causing your problem, but you seem to have isolated it to being related to the trigger deletion.




OK - after a bit more checking I think I can account for the "up by 1" result you are seeing.

MUSHclient executes a script for a trigger, and after the script finishes it adds 1 to the "count of script invocations" for that trigger. You can see this count when you look at a trigger in the trigger window.

You have deleted the trigger while the script was executing, thus invalidating the internal pointer to the trigger structure. Then, when MUSHclient added 1 to the script count, it actually corrupted some piece of memory, as you noticed, or in my case, crashed the client.

I suggest you work around this in a couple of ways:


  • Don't delete the trigger - simply disable it. That is valid, as the trigger still exists.

  • Use "DoAfter" to delete the trigger a moment later, perhaps after disabling it first. That way you are not deleting it while it is executing a script.


I do not really regard this as a bug - self-deleting code will tend to fail in many languages.

- Nick Gammon

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

Posted by Prattler   Lithuania  (15 posts)  [Biography] bio
Date Reply #5 on Fri 13 Jan 2006 11:23 AM (UTC)
Message
Yes, the workaround is really simple. But the bug is so hard to spot that people in the future might have serious problems. What I think would be good is:

Either adding a line in the function descriptions of DeleteTrigger, DeleteAlias, etc. about such usage.
or
Mushclient doing some check to see if the trigger/alias still exists.

Anyway, good thing I got over this :) Was driving me crazy!
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #6 on Fri 13 Jan 2006 04:45 PM (UTC)
Message
Heh Nick. One solution to this glitch would be to flag the trigger/alias/timer as being in the process of executing somehow, then when a delete function is called, generate an actual runtime error, such as:

"<type>(es/s) cannot be deleted while in use. Try disabling the <type> instead."

Since the client wouldn't actually delete it, you avoid the bugs and crashes, while effectively warning people not to do this. This issue has existed for a very long time and I have run into it myself back then. I believe we determined it is safe to do *only* if the deletion happens as the *last* command executed in the script, but that is far from certain either. An error would be far better imho than adding a note to the help file and letting some twit that doesn't read it try anyway.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 14 Jan 2006 12:25 AM (UTC)
Message
It is probably not even safe as the last thing in a script as the "add 1 to script executions" would still happen, randomly adding 1 to some memory location.

I agree it is best if the client does not crash, and have added a test that now stops triggers/aliases/timers from being deleted while they are in the process of executing a script, either in the script file or by "send to script".

This simply returns another error code from DeleteTrigger (or whatever) which you can test for.

This at least stops the crashes, and if are wondering why the trigger is still there you can examine the error code to find out why, and then restructure your code so it doesn't happen.

Also amended the help files to reflect these changes.

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


6,025 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] 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]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]