Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Game Internal Clock HELP  (Read 4564 times)

0 Members and 1 Guest are viewing this topic.

DeScripter

    Topic Starter


    Starter

    • Experience: Familiar
    • OS: Windows 7
    Game Internal Clock HELP
    « on: March 27, 2017, 01:18:18 PM »
    Hi All,

    Thanks in advance.
    I am creating a tomagachi-like game where it is your task to keep the "animal" alive by interacting with the environment and buying supplies at the store. What I would like to add now are "random events" that occur, changing the games environment; and at different times over the course of a game. For example, after playing the game for 45 min, "A snowstorm appears out of nowhere, you have lost all of your food stores!" -- something to that effect.

    I am familiar with using in-game pauses, timeouts, etc, but the problem with all of these is it literally stops the script from continuing to execute code until that command is finished. I have even tried taking the time on the computer clock at one point, taking it again at another point, and calculating how much time has gone by. Anyway, all of these are convoluted and I know there must be an easier way.

    All I need is to program an internal clock that runs in the background (almost like an independent script) that can change aspects at random times. Any ideas?

    -DeScripter

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Game Internal Clock HELP
    « Reply #1 on: March 27, 2017, 04:40:05 PM »
    What language do you use?  c++ ?
    The timer  has no way to pause the time. You have to create some code that will do that for you.

    Here is a link to a forum where users talk about something like whet your want.
    http://forums.gamesalad.com/discussion/43004/countdown-timer-with-pause
    Quote
    If you want to pause the time in a game, you have to use a separate attribute rather than game.time which ALWAYS counts up. So you could change attribute game.elapsed time (real) to game.time when the "press for countdown" button is pressed and then display and pause game.elapsed time instead of game.time.
    Does that help any?


    DeScripter

      Topic Starter


      Starter

      • Experience: Familiar
      • OS: Windows 7
      Re: Game Internal Clock HELP
      « Reply #2 on: April 03, 2017, 01:13:11 PM »
      This was a great answer, unfortunately I forgot to include the language. I am writing this in Batch. This is why it is so difficult!

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Game Internal Clock HELP
      « Reply #3 on: April 03, 2017, 03:30:51 PM »
      Quote
      I am writing this in Batch. This is why it is so difficult!

      Only way to do this would be to have 2 threads going with 2 different scripts. One is a weather script. And its in a loop that after x-many ms it writes a value to a text file, and then goes back into its delay before picking another random number to write to this file that we can call weather.txt

      1 = sunny
      2 = rainy
      3 = windy

      and so on.

      Your batch when it processes the game can read in from text file to a batch variable 1, 2, 3, or another number and depending on the value read in it can then allow for the game to have weather events. But it wont just change. It would require a user to interact with it to refresh its weather value and run that way.

      If your planning on running this on a purely DOS system, a non Windows computer your going to hit a wall with this and batch because in DOS only 1 thing can run at a time unless you get into making a TSR program. Fortunately your probably doing this on a Windows based computer so you can have multiple batch files running at the same time and each interacting with each other by using a text file as a bridge between information from one to the other.

      I made a network turn based program once back in college that used 2 files one file designated whos turn it was to enable the user A or B for being able to make their move to edit the game data file. The other file was the game data file so each users program would refresh from this text file over network share to get the latest move their opponent made.  ;D

      But this network multiplayer game was written in C++ for Windows computers to use a mapped drive that all players had access to, and the turn.txt as a traffic cop to keep only 1 person from editing the gamedata.txt file at a time when not cheating....  ::) and gamedata.txt file was used to keep track of the game play map and who was where and what each persons health and all other stats were at etc.

      The text file over network share was used because I ran out of time and wasnt able to tie this all into a mySQL database. So quick thinking to get the project complete was to go the route of the traffic cop of whose turn it was with turn.txt and gamedata.txt containing the latest info from beginning to game end. Then garbage clean up after game over to reset the gamedata.txt file.

      EDIT: Upon further thought..... was thinking that with this in a loop you could use system time with a rule tied to a random generator used, but its really stretching batches ability here. This way you dont have a timer that is causing a delay in your batch file, but instead based on system time and rules of what to do with that system time from say start of game being 12:15 and at say 12:30 or some other time interval it processes through a different path on your flowchart of the batch files linear but subject to goto execution. This is beyond my batch skills but just thought of it and added it. Batch is limited, in C++ or any other program language this would be way easier, especially in multithreaded programming.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Game Internal Clock HELP
      « Reply #4 on: April 03, 2017, 05:32:00 PM »
      For what it is worth here are some links:
      https://www.raymond.cc/blog/measure-time-taken-to-complete-a-batch-file-or-command-line-execution/
      http://stackoverflow.com/questions/9922498/calculate-time-difference-in-windows-batch-file
      http://www.computerhope.com/forum/index.php?topic=149457.0
      (Ignore my post in the above.)
      For more in depth coverage:
      https://social.msdn.microsoft.com/Forums/vstudio/en-US/430449b3-f6dd-4e18-84de-eebd26a8d668/gettimeofday?forum=vcgeneral
      Quote
      here is total contents.
      The gettimeofday() function obtains the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by . ...
      The gettimeofday() is standard on a UNIX system.  The Windows 2000 rescore kit as a similar thing.
      « Last Edit: April 03, 2017, 05:43:31 PM by Geek-9pm »