Time range in script

I see there are already a timer, but I'ld like to add a control based on current time (i.e. between 18.00-19.00, there are a beautiful sunset, after 19.00 the moon is born... And so on) may be useful to add a time range. It's already possible to do this or may be added in next updates? Thank you.


Do you mean an in-game time, or in the real world?


In real world, the current time of the device, so who is playing in evening, the game ambient is in evening too...


In that case you'd probably want to get the current time from the browser.

I'd suggest some javascript like:

$(function() {
  function updateRealTime() {
    ASLEvent ("UpdateRealTime", new Date().getHours())
  }
  updateRealTime();
  setInterval (updateRealTime, 100000);
});

That sends the browser's time to the Quest backend when the game loads, and then every 100 seconds after that (so you have the current time accurate to within a couple of minutes, while causing minimal disruption to the game. Depending what you're using it for, you might want to increase or decrease the delay.

If you don't want to add a javascript file to your game, you could convert the script above to a single line and put it in your game's UI Initialisation Script (on the Advanced Scripts tab):

JS.eval("$(function(){function e(){ASLEvent('UpdateRealTime',(new Date).getHours())}e(),setInterval(e,1e5)});")

And then on the Quest side, you would have a simple function like this:

<function name="UpdateRealTime" parameters="hour">
  game.realtime = hour
</function>

Then you can use game.realtime in your scripts or in the text processor to see what time it is. It should be a single number, the number of hours since midnight. If you want minutes too, you could make the code a little bit more complex.

Does that do what you want?


Yes, thank you!
Sorry but I'm new in this, my last program I made was in Amos Pro on Amiga 1200 :D
Please can you explain me step by step how to apply that scripts? I attempted to put JS.eval("$(function(){function e(){ASLEvent('UpdateRealTime',(new Date).getHours())}e(),setInterval(e,1e5)});") in game/Advenced Scripts/User interface initialisation... putting it pressing the </> button.
The function I not understand where goes, please make me an example


Sorry, I attempted to do your suggest without success. Now I tought it's better to get the current hour and current minute and store them in two variables at start so I can increase them by a timer, please how I must to do? I already made the timer with controls and works fine but I'ld like to start with real values.


I managed to setup the "player.Ora" attribute (it contains the hour only, no minutes) with current hour, but in timers script, when the attribute being increased, it starts from 0 and not from the value just set by function, I hope had explained good... please help me.


Sorry, I attempted to do your suggest without success. Now I tought it's better to get the current hour and current minute and store them in two variables at start so I can increase them by a timer, please how I must to do? I already made the timer with controls and works fine but I'ld like to start with real values.

OK. The javascript will be a little more complex. So the script in User Interface Initialisation will be:

JS.eval("$(function(){function e(){var d=Date.now();ASLEvent('UpdateRealTime',d.getHours()+';'+d.getMinutes())}e(),setInterval(e,6e4)});")

Are you having trouble creating a function in Quest?
Go to the 'functions' section and press 'new'. Enter the name UpdateRealTime. If you want to change this to something language specific, you need to change it in the script above as well.
For the function parameters, you need to add one and call it time. Then for the function's script, add the code:

time = Split (time)
game.hour = ToInt (StringListItem (time, 0))
game.minute = ToInt (StringListItem (time, 1))

This will give you two attributes, game.hour and game.minute, which contain the current time (to within one minute). If the computer goes to sleep or is in standby, or if the player resets their clock while the game is running, the game will have the old time for up to a minute before it is corrected.


Hi Mrangel, thank you for you patience, I made how you wrote, I placed the script above in User Interface Initialisation, in functions I created new and called UpdateRealTime, added the time parameter and in Return type I choosed Integer, I pasted your script but, i.e., if in room description I write {game.hour} or {game.minute}, the variables are empty.
I need to have hour and minute a once only because I created a time in status; in player/attributes if I set a value, it starts from it and works fine, my problem is I need to set that attributes from real values because the timer increase minutes every 50 seconds, so the game should start with real time but with faster lapse.


I need to have hour and minute a once only

In that case, you have a simpler script:

JS.eval("$(function(){var d=Date.now();ASLEvent('UpdateRealTime',d.getHours()+';'+d.getMinutes())});")

In this case, you will probably want to put it in your game start script. (Putting it in UI Initialisation script would make it skip to the current time when the player loads a saved game)


Thank you, I made it but I continue have the game.hour and game.minutes variables empty, I test them adding {game.hour} in a room description... My bigger problem is: how I can tranfer their values to player.Ora and player.Minuto attributes to start with them?


Sorry, I made a careless mistake.

In the code above, change Date.now() to new Date().

My bigger problem is: how I can tranfer their values to player.Ora and player.Minuto attributes to start with them?

You can just change the attribute names in the function.


Hi, mrangel, finally you solved my issue, thanks a lot!
I attempted to save position to see if saves the current time game but I encountered an error: Unable to save the file due to the following error: Function not found: 'case'


Ok, this time I solved myself, I seen another topic where you rewrote the Possessive function in Italiano.aslx file but there was still a problem with two duplicate cases, I replaced that in line 657 case ("lei la") with case ("lei lo"), it works fine now.
A last issue, if I resume the position, the time restarts from current real time, where can I move the script so that it is skipped when I resume the game?


A last issue, if I resume the position, the time restarts from current real time, where can I move the script so that it is skipped when I resume the game?

I already mentioned this. You need to move the JS line from the UI Initialisation script to the Start script.


Ok, done! Thank you!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums