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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Attempting to create a percent-to-time script

Attempting to create a percent-to-time script

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


Posted by Faedara   (106 posts)  [Biography] bio
Date Sun 17 Apr 2011 02:09 AM (UTC)
Message
I have a rather large and complicated scheme going for a script I've built to tell me how long I have until completing the current project I'm building in the MUD, but I've been having multiple problems with the math part of the equation, some of them being because I don't know how to convert everything into the proper formats. Right now I have this:


<aliases>
  <alias
   match="ptest"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTrigger("test1", true)
Send("list")
DoAfter(1, "list")
EnableTimer("math", true)
ResetTimer("math")</send>
  </alias>
</aliases>

<triggers>
  <trigger
   expand_variables="y"
   keep_evaluating="y"
   match="^(.*?) taken\) (.*?)\% Complete$"
   name="test1"
   regexp="y"
   send_to="12"
   sequence="99"
  >
  <send>test1 = "%2"
Note (test1)
EnableTrigger("test1", false)
ResetTimer("test2")
EnableTimer("test2", true)</send>
  </trigger>
  <trigger
   expand_variables="y"
   match="^(.*?) taken\) (.*?)\% Complete$"
   name="test2"
   regexp="y"
   send_to="12"
   sequence="99"
  >
  <send>test2 = "%2"
Note (test2)
EnableTrigger("test2", false)</send>
  </trigger>
</triggers>

<timers>
  <timer name="test2" second="0.50" offset_second="0.00"    send_to="12"
>
  <send>EnableTrigger("test2", true)
EnableTimer("test2", false)</send>

  </timer>

  <timer name="math" second="2.00" offset_second="0.00"    send_to="12"
>
  <send>test3 = 100/(test2-test1)
Note "Total time:"
Note (test3)
Note "Remaining time:"
EnableTimer("math", false)</send>

  </timer>
</timers>


The goal is to take this line:
Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) 18.33% Complete
Two times (one second apart) and get the % from it each time, then examine the difference and convert that into a time estimate (it doesn't have to be exact but thus far it's been anything but accurate). Some of it I accidentally lost when copying these here (I tend to leave bits of code on my copyboard) so the math timer is now completely broken.
If anyone can help me figure out where I'm going wrong, how to convert the end product into time, or give me general tips for fixing this heaping mess of newbstink, it would be greatly appreciated.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Reply #1 on Sun 17 Apr 2011 03:12 AM (UTC)
Message
the almighty GetInfo (232) will get you accuracy!
(try doing a few Note(GetInfo(232))'s in the immediate screen to get the idea)

I noticed that you're looking for a "mentor" (it's in your signature) ... I'm not a pro but I might be able to give you some tips I've learned so far!

You can add me on AIM: AlexRaato

I got this!
[Go to top] top

Posted by Faedara   (106 posts)  [Biography] bio
Date Reply #2 on Sun 17 Apr 2011 03:18 AM (UTC)
Message
Sorry but I don't get how that's supposed to help me at all...

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Reply #3 on Sun 17 Apr 2011 03:54 AM (UTC)
Message
make an alias to start it up, make the alias send whatever command that invokes the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) 18.33% Complete" thing, the alias should also enable trigger1 and add a timer to disable it and prompty enable trigger2

trigger1 (responds to the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) *% Complete" string)
time1 = GetInfo(232)
percent1 = *

trigger2 (responds to the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) *% Complete" string)
time2 = GetInfo(232)
percent2 = *

periode = time2 - time1
growth = percent2 - percent1

to_go = 100 - percent2
time_until_done = to_go/periode


is that of any help? I can try to write some code for you if you'd prefer that

I got this!
[Go to top] top

Posted by Faedara   (106 posts)  [Biography] bio
Date Reply #4 on Sun 17 Apr 2011 03:59 AM (UTC)
Message
And now it all makes perfect sense... well played.
Only one problem, when I subtract a number with a decimal from a number with a decimal it comes out with unprovoked infinite number syndrome.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Reply #5 on Sun 17 Apr 2011 04:51 AM (UTC)
Message
this ancient scripture might hold the answer:
http://www.gammon.com.au/forum/?id=7805

I got this!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sun 17 Apr 2011 05:11 AM (UTC)

Amended on Sun 17 Apr 2011 05:12 AM (UTC) by Nick Gammon

Message
And more self-documenting if you are using a recent version:

http://www.gammon.com.au/scripts/doc.php?lua=utils.timer


It came out in version 4.62.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sun 17 Apr 2011 05:13 AM (UTC)
Message
Faedara said:

Only one problem, when I subtract a number with a decimal from a number with a decimal it comes out with unprovoked infinite number syndrome.


Subtracting two numbers should never give you infinity. Are you sure you didn't do a divide in there somewhere? (Or if the two times are the same then subtracting one from the other gives you zero, which then might eventually lead to a divide by zero).

- Nick Gammon

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

Posted by Faedara   (106 posts)  [Biography] bio
Date Reply #8 on Sun 17 Apr 2011 06:31 AM (UTC)
Message
Maybe infinite alone is the wrong word for it, it's actually returning a randomly repeating decimal such as if I do:
12.34-12.30 I might get something like 0.049999999

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Faedara   (106 posts)  [Biography] bio
Date Reply #9 on Sun 17 Apr 2011 06:43 AM (UTC)
Message
Aha! I finally figured out what was wrong with my original script. The MUD updates on even seconds, so I had to take the result of a one second scan and then divide that by two for the rest of the equations!

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #10 on Sun 17 Apr 2011 09:34 AM (UTC)

Amended on Sun 17 Apr 2011 09:43 AM (UTC) by Twisol

Message
Faedara said:
Maybe infinite alone is the wrong word for it, it's actually returning a randomly repeating decimal such as if I do: 12.34-12.30 I might get something like 0.049999999

Well, the 9's don't continue infinitely. That missing 0.0000000000000001 (or so) is called "epsilon", which is the resolution of a floating-point number. (It's not a constant like e or pi is, though: it depends on how many bits are used.) When you do any kind of arithmetic with floating point numbers, you necessarily involve some amount of inaccuracy, because there are some values that can't be stored precisely.

[EDIT]: The tl;dr is, the inaccuracies you're seeing are expected side-effects of floating-point numbers.

[EDIT] 2: http://en.wikipedia.org/wiki/Machine_epsilon

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[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.


29,315 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 HostDash]