How do I print the value of a timer?

Hi, I'm trying to make a game where you can see how long you've been somewhere using a watch given to the player. The result I'm looking for is that the player can look at the watch and see the time in the description.

At the moment, I have a timer with an interval of '1' and a script that should set a variable 'watchtimer' to the value of the timer.
Then, when you look at the watch, it will use that variable to display the time.

Another issue I found is that when I try to assign the variable to anything using the timer (which starts when the game begins for now), even if it's an integer, it will run an error saying that the variable 'watchtimer' is unknown. The spelling and capitalization is consistent throughout.

Any ideas on how to make this work?
Thanks!


Variables only exist until the end of the script that created them. So you create a variable, and it goes away again immediately.

You need to make it an attribute by attaching it to an object. For example, using game.watchtimer as your variable name will make it exist as long as the object game does.

If you have problems with that, it would probably be better to post the code that's giving you a problem, so we can have a clearer idea what's going on.


Thank you! I've gotten everything working now.

Solution: I had to set game.count, which stores the watch's timer value, to game.count + 1 in the timer script so it would increase by 1 every second to create a value for the timer that can be printed.

Not sure if there's an easier way to do that (e.g. being able to print the timer's value without making a new attribute), but that worked for me.


Not sure if there's an easier way to do that (e.g. being able to print the timer's value without making a new attribute), but that worked for me.

What do you mean by "the timer's value"?
A timer is a script that runs at a certain time; it doesn't have a value.

Do you mean the built-in attribute game.timeelapsedwhich contains the number of seconds since the game started?


Log in to post a reply.

Support

Forums