Demintika 63 Posted February 3, 2015 I was playing with Thread and come up with this script.Introduction: A script that creates a digital clock on a corner of the screen,constantly reminds the player what time it is.The time displays is the player's computer's current time.Use: Plug and Play. Also, there are some script you can use: Clock.position = new-position Moves the clock to the new position. new-position can be 0 or 1 or 2 or 30 - Upper left1 - Upper right2 - Down left3 - Down right Clock.stop Clock.run Hides and shows the clock.Script: http://pastebin.com/a90gL43M Share this post Link to post Share on other sites
starwarrior00 0 Posted February 3, 2015 Is this script allowed in commercial games? Share this post Link to post Share on other sites
Demintika 63 Posted February 4, 2015 Is this script allowed in commercial games? It's just a simple script, and I'm scripting for fun and experience, so just have my name in the credit is fine. Share this post Link to post Share on other sites
Gamingstar 1 Posted March 13, 2019 (edited) is the current time able to be set as a variable? Edit: Just realized how old this post is, so I don't expect a reply Edited March 13, 2019 by Gamingstar Share this post Link to post Share on other sites
Rikifive 3,411 Posted March 13, 2019 2 hours ago, Gamingstar said: is the current time able to be set as a variable? Assuming, that I'm thinking of what you're thinking of~ I've added a method to return the current time as a string. For example, @variable => nil (not set) @variable = Clock.current @variable => "07:23" That method doesn't affect the clock's behavior, it just returns the current time. Here's the slightly modified script: Spoiler #============================================================================== # * Config #============================================================================== module Clock #-------------------------------------------------------------------------- # |0 1| # | | # | | # |2 3| #-------------------------------------------------------------------------- @position = 0 #-------------------------------------------------------------------------- # You can change position later with Clock.position = new-position # Example: Clock.position = 2 #-------------------------------------------------------------------------- # You can save the current time into a variable with @var = Clock.current #-------------------------------------------------------------------------- #============================================================================== # * Config Ends. #============================================================================== #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.position=(pos) @position = pos @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.current time = Time.now return sprintf("%02d%s%02d", time.hour, ":", time.min) end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.clock_pos x = @position % 2 == 0 ? 0 : Graphics.width ox = x == 0 ? 0 : 50 y = @position / 2 == 0 ? 0 : Graphics.height oy = y == 0 ? 0 : 24 return x, ox, y, oy end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.start @clock = Sprite.new @clock.z = 1000 @clock.x, @clock.ox, @clock.y, @clock.oy = *clock_pos @bitmap = Bitmap.new(50,24) @clock.bitmap = @bitmap end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.update time = Time.now tick = (time.sec % 2 == 0) ? " " : ":" return if @tick == tick @tick = tick text = sprintf("%02d%s%02d", time.hour, tick, time.min) @bitmap.clear @bitmap.draw_text(0,0,50,24,text) end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.stop @clock.visible = false @updater.stop end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- def self.run @clock.visible = true @updater.run end #-------------------------------------------------------------------------- # * #-------------------------------------------------------------------------- start unless @updater @updater = Thread.new { loop do sleep(0.1) Clock.update rescue start end } end end #============================================================================== # * #============================================================================== By the way the clock is not updating properly for me for some reason. It refreshes every 1~6 seconds, so the " : " between numbers acts weirdly and the clock tends to be off-sync by these few seconds. Either way, I didn't touch anything, I left it be like it was originally written. Hope that helps. c: 2 Share this post Link to post Share on other sites
PhoenixSoul 1,404 Posted March 14, 2019 This is actually really cool. I actually wonder what @Kayzee would think of this... Share this post Link to post Share on other sites
Kayzee 4,033 Posted March 15, 2019 What I think? I think I have seen scripts like this before, but never thought it was particularly useful to use the computer's real time unless you are making something like Animal Crossing. That said, it wouldn't be hard I think to modify it to use an in-game timer. The nice thing about Ruby's Time class is you can use it to do math with times and dates! 2 Share this post Link to post Share on other sites
PhoenixSoul 1,404 Posted March 15, 2019 Or, a Pokémon game that has Gen. 4+ features in the save files... Share this post Link to post Share on other sites
roninator2 257 Posted March 17, 2019 On 3/15/2019 at 9:10 AM, Kayzee said: never thought it was particularly useful to use the computer's real time Just had a thought... What if you used it for a fourth wall breaking game. You play the game and check that it's 2am, you put up a text "don't you ever sleep?" 2 Share this post Link to post Share on other sites
Rikifive 3,411 Posted March 17, 2019 Some games offer displaying real time somewhere in the HUD and personally I find it kinda useful, even though I have a physical clock right in front of me. It also depends on the type of game; You mostly see these in MMO's of some sort, where the HUD is relatively large. With that being said, how the time is displayed in this script isn't necessarily convenient, but with some proper modification, it would be possible to nicely include it somewhere, where it would look good. There are legit usages depending on worldbuilding and the type of game. For example, day/night cycle based on real time. It could have impact on the gameplay, like more&stronger enemies appearing in the woods; ghosts or whatever. Or if one wouldn't like the time to make a difference, it could be just about visuals only. Perhaps some players would appreciate having darker colors when playing at night. 5 hours ago, roninator2 said: What if you used it for a fourth wall breaking game. You could also use it for Easter Eggs. Let's say you're playing a game and everything is cool; Then 3AM comes in and if you happen to be in a specific place in the dark forest, something odd may happen. Think of some creepypasta content of some sort. 2 Share this post Link to post Share on other sites
Kayzee 4,033 Posted March 17, 2019 Hehe, not saying it isn't useful at all, it just seems a bit gimmicky to me to do stuff like that. I mean, one thing I think is fun about Nethack is that the calculated current phase of the moon has an effect on the game. Like a full moon making werecreatures stronger. But I personally think I rather it be random or based on the number of times played or some in game date rather then the real date. I was playing with making a script to calculate a lunisolar calendar for my game actually, but I am pretty sure I am not going to use the actual computer time. Partly because my game is turn based anyway, partly because the season will likely effect some things and I don't want players to be forced to deal with it for playing at a particular time of year, and partly because I kind of want to use time as a sort of resource (like for example maybe dying will cost you a day or a week of time). 1 Share this post Link to post Share on other sites