x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How To Tell How Much Time Has Passed?

G'day,

A quick question that probably has a simple answer. Using the datetime functions (https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/DateTime/index.html)

How can I tell how many minutes have passed?

I have a save file for a game, which stores the datetime that it was created. I'd like to check the difference in time between the save files datetime and the current time to see if it's been more than say, ten minutes. If it has, do this, if it hasn't, do that.

Any help is appreciated!

Product Version: UE 4.9
Tags:
more ▼

asked Sep 12 '15 at 06:58 AM in Blueprint Scripting

avatar image

reznorism
11 2 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

There are two ways to do this:

One is to get the actual system time (as you probably did) using the Now node, which returns a Date Time Structure, presumably something of the form Year-Month-Day-Hour-Minute-Second. Given such a Date Time Structure, you can then query the elements (GetDay, GetHour, GetMinute). So you could implement a function that checks the difference between two such structures by comparing all the date elements. You'll need to pay attention to overflows: obviously more than ten minutes have passed from 15:23 to 15:42, but the same is true for 15:57 to 16:08. When testing your function, you can manipulate your system clock to test whether you catch all such cases correctly. (Or you might decide that it's okay if there are some edge cases, such as rolling past midnight, where you just don't care.)

Alternatively, you could use Get Real Time Seconds (since the session has started) and compare the differences between two second counts. Converting to minutes is easy in this case.

https://docs.unrealengine.com/latest/INT/BlueprintAPI/Utilities/Time/GetRealTimeSeconds/index.html

more ▼

answered Sep 12 '15 at 08:17 AM

avatar image

erinacea
1.8k 69 28 113

avatar image reznorism Sep 12 '15 at 12:46 PM

Awesome, thank you erinacea =) I will give it a whirl and report back!

avatar image reznorism Sep 13 '15 at 04:33 AM

Having some serious trouble working this one out, any more help is appreciated =)

Basically, I have a merchant NPC in place that the player can buy/sell goods to. When they leave the merchant, it currently resets what he has for sale. But what I want to do, is save the date and time that they left the NPC (already doing) and if they come back and it's been less than say 10 minutes the current inventory with the items the player sold are in it. But if its been more than 10 minutes, the merchants items have reset.

It's to give the player an opportunity to re-buy items if they accidentally sold them.

avatar image erinacea Sep 13 '15 at 10:42 AM

That's probably easier using a Timer node.

When your character leaves the shop start a Timer to call ResetInventory (or whatever) after 10 minutes (600 seconds) have passed. If the character returns while the timer is still running, stop the timer.

alt text

I haven't actually used timers yet in Unreal 4.9, but the system looks fairly straightforward. In a quick test, I didn't get any errors or warning trying to clear an uninitialized handle (when first entering the shop, the variable hasn't been set yet).

If you need to save the timer to continue at the same time when loading a savegame, you can use Get Timer Remaining Time and save the returned float value. Then when loading your savegame and this value is greater than zero, simply restart the timer (using Set Timer By Event) with the remaining time instead of the full 10 minutes.

alt text

Good luck!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question