Message from JavaScript discussions

April 2019

— Https://


I need to think on that, I didn't understand what you ment in 100 percent but it's not your fault, I'm still new in this

— I basically need an easy access everywhere in the js file to the updated version of newGame.startTime

Message permanent page

— Ok, you will always have an updated version, but if you pass it to a function it will stay the same because it will not pass a “pointer” and instead will evaluate the expression at that time.

You could pass the reference of your object.

play(game) {
this.interval = setInterval(() => {
return this.startTime
}, 1000)

Message permanent page

— I think I got your point, I will give it a try and hopefully it will get me the correct results

— elxris thanks a lot for the help!

— You’re welcome 🎉

— May I ask your opinion about one more thing... I made this fake time to have actions of the game's characters measured and executed in accordance to that time, there will be even an option to speed up the time that's why I added newGame.pace parameter. The idea is similar to those mobile games that you choose to do an action and it measures and counts the time that is left to execute it. i also want to do it in OOP style.

So I'm wondering if I am going in the right direction?

Ps. the class Game has a constructor so the user can save the games and load them later.

Message permanent page

— I think you’re in good direction, but I never tried to implement something like that. It takes trial and error.

Message permanent page

— elxris I DID IT! now it finally works

— Check the timeout in the last line

— It checks the time after the function is paused