How do I get my project to know the date?

Get help using Construct 2

Post » Tue Apr 15, 2014 10:55 pm

Hey all,

I need my project to know the date; can this be done with c2?
B
29
S
6
G
5
Posts: 249
Reputation: 5,578

Post » Tue Apr 15, 2014 10:59 pm

c2var date = browser.execjs("var d; d = new time(); d;")

You can make a browser javascript call. Or you an use a plugin.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Tue Apr 15, 2014 11:33 pm

Thank you for the response, jayderyu! If I understand you correctly, you've provided an example of a javascript call that will produce a variable called "date", and provide the actual date as that variable. Unfortunately, I have no idea how to implement this in a C2 project. C2 doesn't even recognize ";" as a valid input for a variable.

Likewise, I'll need to be able to create variables relative to the date, e.g. 2 days ago, 1 month, etc. Any thoughts on this? I'm hoping this can be accomplished without too much difficulty. Thanks again!
B
29
S
6
G
5
Posts: 249
Reputation: 5,578

Post » Wed Apr 16, 2014 1:12 am

This is embarassing...I found the answer right here:

https://www.scirra.com/tutorials/940/ho ... -a-project

I actually found this by googling: browser.execjs --> it's the top result!

Thanks again, and I'll try to delve deeper into the forum search bar prior to making future posts :oops:
B
29
S
6
G
5
Posts: 249
Reputation: 5,578

Post » Wed Apr 16, 2014 2:39 pm

I've done the same thing. C2 has no in built system for date and time. It's not like your question was about applying behaviours :D

Rex's plugin is good too.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Wed Apr 16, 2014 3:35 pm

A built in function for it would be nice. Until then the plugin can be found here:
viewtopic.php?t=63492&start=0
B
53
S
16
G
6
Posts: 718
Reputation: 9,150


Return to How do I....?

Who is online

Users browsing this forum: Apollo14, MaujDeveloper and 5 guests