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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Attempting to create a percent-to-time script
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Attempting to create a percent-to-time script
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Sun 17 Apr 2011 09:34 AM (UTC)  quote  ]

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

Posted by Faedara   (104 posts)  [Biography] bio
Date Sun 17 Apr 2011 06:43 AM (UTC)  quote  ]
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 Faedara   (104 posts)  [Biography] bio
Date Sun 17 Apr 2011 06:31 AM (UTC)  quote  ]
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 Nick Gammon   Australia  (19,188 posts)  [Biography] bio   Forum Administrator
Date Sun 17 Apr 2011 05:13 AM (UTC)  quote  ]
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 Nick Gammon   Australia  (19,188 posts)  [Biography] bio   Forum Administrator
Date Sun 17 Apr 2011 05:11 AM (UTC)  quote  ]

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 Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Sun 17 Apr 2011 04:51 AM (UTC)  quote  ]
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 Faedara   (104 posts)  [Biography] bio
Date Sun 17 Apr 2011 03:59 AM (UTC)  quote  ]
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 Sun 17 Apr 2011 03:54 AM (UTC)  quote  ]
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   (104 posts)  [Biography] bio
Date Sun 17 Apr 2011 03:18 AM (UTC)  quote  ]
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 Sun 17 Apr 2011 03:12 AM (UTC)  quote  ]
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   (104 posts)  [Biography] bio
Date Sun 17 Apr 2011 02:09 AM (UTC)  quote  ]
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

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.


3,076 views.

[New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]