设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 111|回复: 0

[转载发布] Get, compare, and store System Time

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-2 10:40:34 | 显示全部楼层 |阅读模式
    Hello!

    Today, out of necessity, I had to try my hand at creating my very first Ruby script. It's only small, but I thought that some people who have no scripting knowledge might find it useful. I am pretty sure that it is bug free, since it's difficult to put many bugs into so few lines. I don't know if something like this exists already, but if it does, I was unable to find it. Maybe someone else will have a use for it too.

    If people want me to add other date functions (such as converting the timestamp this script gives you into an actual date with day, month, year, etc) I can do that.

    What it does

    I was looking for a method to count the passing of seconds in the game. This is possible through eventing and using a wait command in a loop, however I had trouble with the accuracy, and it also had a very serious fault...if you tab out of the game (or quit, obviously), the wait command will pause and therefore mess up your calculations. To solve this, I created a script that can keep track of time even when the game events aren't running. It does so by simply taking the system's current time and putting it into a variable whenever you call the method. It also contains a second method that allows you to use this variable and find out how much time has passed since you stored the last time...and put the result in seconds into another variable.

    Possible uses

    You could use it to keep track of how long a BGM/BGS/ME/SE has been playing to stop it at a specific time - since the audio keeps playing even if you tab out of the window (that was my original problem), or you could let the player know how long it has been since they last played the game, make your actors yell at the player if they haven't played in days, or show how much lifetime they have already invested in your pixels,...Basically, whatever you can think of.

    Screenshots









    How to use

    The script gives you two methods to work with:

    get_time(variable_id)You can use this in an event with the call script command. Replace variable_id with the ID of the variable you want the current time (in seconds since 1970) stored in, and this variable will receive the data.

    compare_time(variable_then,variable_difference)This will let you store the difference in seconds between the value the first method gave you and the current time. Replace variable_then with the ID of the variable where you stored the time, and variable_difference with the ID of the variable you want the result to be stored in.

    That's it. You can also find the instructions in the script itself.

    The actual script

    Spoiler##################################### Time to Variable Script# by autophagy##################################### VERSION: 1.0 created 9th June 2014##################################### DESCRIPTION:# Can save the current time as a timestamp into a variable and compare it.# I was trying to figure out a way to measure the passing of seconds ##################################### INSTRUCTIONS:# *Use get_time(variable_id) in a script call to save current timestamp in a #   variable.#   Replace variable_id with the id of the variable you want the time to be stored #   in.# * Use compare_time(variable_id_stored,variable_id_difference) to compare stored #     timestamp to current time.#     This will substract the stored variable with the id variable_id_stored #     from the current timestamp and put the difference in seconds into the #     variable with the id variable_id_difference.# * Go wild.###################################### DON'T TOUCH THIS#####################################def get_time (variable_id)  now = Time.now.to_i  $game_variables[variable_id] = nowenddef compare_time(variable_then,variable_difference)  now = Time.now.to_i  $game_variables[variable_difference] = now - $game_variables[variable_then]end################# end of script################ 



    Have fun! Please credit me if you use this script.


    本贴来自国际rpgmaker官方论坛作者:autophagy处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/get-compare-and-store-system-time.28171/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 12:38 , Processed in 0.107344 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表