Why can't events take large numbers?

Post Reply
Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Why can't events take large numbers?

Post by Jor'Mox »

When I use raiseEvent, and try to pass a numerical argument (or a string that can be represented as a number), any number over 999999 is instead passed as 0. Why is there such an arbitrary upper limit?

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: Why can't events take large numbers?

Post by Akaya »

Tried this out myself. Same result. Very odd.

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

Re: Why can't events take large numbers?

Post by Vadi »

There is no limit on this that I remember, but it's not something I've ran into - I'll check this out when I can.

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

Re: Why can't events take large numbers?

Post by Jor'Mox »

I ran into the issue while trying to pass experience totals via an event. It was working fine until people were reaching higher levels, where it would suddenly stop working. So I made a simple function that would display an argument passed to it via an event. Then I just gave it bigger and bigger numbers until it stopped working. Initially I did powers of two (thinking there might be some variable size limiting issue). Once I was over 1,000,000 I was seeing 0 instead, and boundary testing revealed it wasn't the closest power of two where the problem showed up, but at exactly 1,000,000. To be sure other possibly related functions weren't to blame, I successfully used numbers over 1,000,000 with tonumber, pcall, and the variable argument syntax (...), and display. I also tested with numbers without a bunch of zeros in case it was truncating, rather than just setting to zero. 1,111,111 also gets passed as zero, so it has to be just getting set to zero.

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

Re: Why can't events take large numbers?

Post by Vadi »

The issue comes from the code doing a toInt() in one place on Lua numbers which are double by default. Internally, a numbe like 1000000 gets converted into 1e+06 on which toInt() gives 0. toDouble() gives the proper result, so it is an easy fix. I'm not sure why is the original code doing this.

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

Re: Why can't events take large numbers?

Post by Jor'Mox »

Oh, wow, I didn't even notice that it also set numbers with decimal parts to 0 (but I double checked, and it does). Thanks for checking this out Vadi. :-)

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

Re: Why can't events take large numbers?

Post by Vadi »

Yeah. This'll be fixed next release: https://github.com/Mudlet/Mudlet/commit ... c64163a8a7.

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

Re: Why can't events take large numbers?

Post by Vadi »

This is fixed in the upcoming 3.0 release, you can grab the preview of it at http://www.mudlet.org/download.

Post Reply