Jump to content

Recommended Posts

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 3
0 - Upper left
1 - Upper right
2 - Down left
3 - 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
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:

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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?"

Share this post


Link to post
Share on other sites

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. :P  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. dfEG13d.png

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. dfEG13d.png Think of some creepypasta content of some sort.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×