mm2 timestamp usage

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
User avatar
lisa
Posts: 8330
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

mm2 timestamp usage

#1 Post by lisa » Thu Dec 17, 2015 7:28 pm

Ok So I have been browsing the wiki and checking out the timestamp class, would this now be the preferred way to track times?

So in my current project I am still using the dt

Code: Select all

function macro.main(dt)
	gaptime = gaptime - dt
	walktime = walktime - dt
if gaptime < 0 and walktime < 0 then
Or is the timestamp class now the better option?

Didn't really find any examples of timestamp usage but there seems to be a few ways of going about it.

You could add the seconds to now time and then use Timestamp:isPast to see if the time is after what you are looking for.
You could add the seconds to now time and then use Timestamp:diffInSeconds in comparison to now time.
You could set now time to a variable and then use Timestamp:diffInSeconds to compare to now and see if the time you wanted has passed.

I am thinking for what I want the first option will work as it only has 1 variable to keep track of, you just set the time + the number of seconds added to it and then check if that time isPast or not.

Any advice on the way you intended it for use?

This is so different to just doing a yrest in the code, so much more to think about but at the end of the day it is a better way to do things.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: mm2 timestamp usage

#2 Post by Administrator » Thu Dec 17, 2015 11:15 pm

Sure, it's really good for timing tasks, but only has second precision; not high-precision (sub-second). This might be changed in the future.

isPast() can be used to tell if it has elapsed (or "triggered", if you're using it to time a task), but you can also use < (isPast), <=, == (isNow), > (isFuture), or >= on timestamp objects. Open up lib/timestamp.lua and browse through the different functions.

Code: Select all

if( myTimestamp > Timestamp:now() ) then
    -- This happens when myTimestamp is in the future
end

User avatar
lisa
Posts: 8330
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: mm2 timestamp usage

#3 Post by lisa » Fri Dec 18, 2015 2:37 am

testing with this atm, seems to be fine but this is very simple, just does a mouse click every 30 seconds.

Code: Select all

			if timer:isPast() then
				mouse.setVirtualPosition(win, clickw, clickh)
				mouse.virtualPress(win,  key.VK_LMOUSE,true)
				timer = Timestamp:now():addSeconds(waittime)
			end
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: mm2 timestamp usage

#4 Post by Administrator » Fri Dec 18, 2015 1:17 pm

If you're just doing simple operations like that, you can make use of the taskqueue (see: lib/taskqueue/), I know I've made a post about how that all works somewhere... It was kind of experimental and I haven't touched it in awhile, but might help to simplify your code further. Basically you create a task and register it with the queue; it will automatically handle launching the tasks for you.

User avatar
lisa
Posts: 8330
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: mm2 timestamp usage

#5 Post by lisa » Sat Dec 19, 2015 2:12 am

Found it
http://www.solarstrike.net/phpBB3/viewt ... eue#p58747

and yeah that will pretty much do what I want ;)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest