Total Playing Time Variable Control

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
I am not sure if this has been asked or not, but surely I have used Google with "site:forum.rpgmakerweb.com" in the search keyword tail everytime I searched for this question. It could be that this question is too easy to answer or may be I am just bad with keyword searching.

Anyway, here is the case:

Let's say I want to spawn an enemy in a room when the total playing time is 3600 seconds (and up), except if you manage to turn off one switch in that room before the total playing time reaches 3600 seconds. But that's not everything; turning off the switch in that room will just delay the enemy spawn for ....hmmm.... let's say 1800 seconds.

So here what I did:

For the part where the enemy spawn after 3600 seconds unless you turn off the switch is quite easy

0. Created a switch called "start", and set it to ON when the game starts using auto run effects.

1. Created a common event called "whatever" with parallel process on "start" switch.

2. Created a switch called "delay" and variable called "playing time"

2. In "whatever", made a conditional branch in which if switch called "delay" is ON, then "playing time" is set to 0, else, "playing time" is set to "play time"

3 Created the switch event on that room with action button trigger that will turn the switch called "delay" and self switch A on.

4. Created the enemy event on that same room with "playing time" condition = 3600 or above.

Done, at least for the first part.

Now, instead of setting "playing time" to 0, I would want it to be set to "play time - 1800".

I have tried:

1.  $game_variables[n] = $game_system.playtime_s - 1800 on script call in "whatever" conditional branch, and it gives out error when I turn off the switch in that room.

2. $game_variables[n] = Time.now.to_i - 1800 on script call on script call in "whatever" conditional branch, and nothing happened!

What should it be?

Guess....I am such a big newbie in scripting lol.

Thanks for at least reading!
 

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
Hi, I just have a few questions regarding your scenario.

 

1) Will this scenario be used only in a few maps, or will it be prevalent throughout your game?

2) Is the enemy involved in this scenario one-time, or will there be multiples all over the same map, area or game?

3) Do they have the ability to respawn?

4) If they can respawn, and you have multiples of this kind of enemy, will they respawn :

     a) at the same time regardless of when they were defeated when the counter reaches the specified time; or

      B) separately depending on the time or order they are defeated?

 

Thanks for your time.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Hi - you should definitely answer Susan's questions so we can further help you event this out, but I think I know what's going wrong with your syntax.

$game_system.playtime_s returns a String in hh:mm:ss format so you can't subtract a number from it.  Instead, use $game_variables[n] = $game_system.playtime - 1800 and that should work.  I'm not totally sure you're using the right math behind it anyhow (I'd simply have the switch set the number to 1800 rather than playtime - 1800, so you can guarantee there will be 1800 more seconds until you hit 3600), but hopefully this will get you past the syntax problems.
 

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
Hi, I just have a few questions regarding your scenario.

 

1) Will this scenario be used only in a few maps, or will it be prevalent throughout your game?

2) Is the enemy involved in this scenario one-time, or will there be multiples all over the same map, area or game?

3) Do they have the ability to respawn?

4) If they can respawn, and you have multiples of this kind of enemy, will they respawn :

     a) at the same time regardless of when they were defeated when the counter reaches the specified time; or

      B) separately depending on the time or order they are defeated?

 

Thanks for your time.
1. Prevalent throughout the game. That's why I am thinking of using common event running on parallel process.

2. There will be multiple of enemies. Some enemies will have different spawn time. That's the reason I created enemy event with Variable called "playing time" that's set to Play Time = 3600 as its event condition. Some other enemies will have 7200, 10000, etc...

3 and 4. Nope, no respawn. At least not now lol. It is already too complicated for me by now~~

Thanks for your reply~~

Hi - you should definitely answer Susan's questions so we can further help you event this out, but I think I know what's going wrong with your syntax.

$game_system.playtime_s returns a String in hh:mm:ss format so you can't subtract a number from it.  Instead, use $game_variables[n] = $game_system.playtime - 1800 and that should work.  I'm not totally sure you're using the right math behind it anyhow (I'd simply have the switch set the number to 1800 rather than playtime - 1800, so you can guarantee there will be 1800 more seconds until you hit 3600), but hopefully this will get you past the syntax problems.
Hi,

Can't believe there are replies to my topic already lol, I thought it will take some more while before one reply even comes out for this kind of question~

$game_variables[n] = $game_system.playtime - 1800 doesn't work either. I think the reason it doesnt work is because the " - 1800" part gets into second line in the script call due to line break.... damn.

There is a problem with setting the Variable (called "playing time") to 1800 in common event's parallel process; it will cause the game play time practically stops at 1800 without any chance of increasing to 3600.....
 
Last edited by a moderator:

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
Hi, thanks for your response!

 

I've tried out Wavelength's script call and it works well. I didn't see any line break.

Please try out the event process below.

 

1) Create an event that will autorun when the game starts.

    - Under Contents, create Control Switch "Start" to "ON".

    - Create a 'New Event Page' and select Switch "Start" is ON. Leave the page blank.

 

2) Create a common event with a "Parallel Process" trigger on "Start" Switch.

    - Under Contents, create a Conditional Branch

        -> Select Switch "Delay" is "ON"

        -> Make sure 'Set handling when conditions do not apply' is checked.

        -> Click on the space directly under 'Condition Branch: Switch [Delay] == ON'.

                -> In the Event Commands, click on tab '3'.

                -> At the bottom right is an command 'Script', click on that.

                -> Type in "$game_variables[1] = $game_system.playtime - 1800" without the inverted commas and click 'OK'.

        -> Click on the space directly under 'Else'. You can either use :

                 a ) Control Variables "Playing Time" "Set" "Game Data -> Play Time"; or

                 b ) Use the script command and type in "$game_variables[1] = $game_system.playtime" without the inverted commas.

                 Both achieve the same thing.

 

3) Create the 'switch' event.

 

4) Create the 'enemy' event.

 

Thanks to Wavelength for his script call.

Hope this helps.
 

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
@Susan

thanks for the reply

I have furthered tested these code

$game_variables[1] = $game_system.playtime - 1800
and I found out that it doesn't work.

Surely "$game_variables[1] = $game_system.playtime" and "$game_variables[1] = 0" or "$game_variables[1] = 1800" works well, but it just doesn't work when you put both of them together in "$game_variables[1] = $game_system.playtime - 1800"

Here is the test I made to prove it:

0. Make new game project.

1. Create an autorun event.

2. In that autorun event, make a switch called "start" and turn it on in the content. After that, in that same event's content, turn the self switch = A ON. Self Switch A On will redirect to empty event page.

2. Create a common event with parallel process condition that's triggered when "start" switch is ON.

3. In that common event, using conditional branch, make it so that when a switch called "delay" is ON, then $game_variables[1] = $game_system.playtime - 10 , else: $game_variables[1] = $game_system.playtime

4. Create a switch event with action button trigger, in which when player clicks on it, this event will turn a switch called "delay" ON.

5. Create an NPC, that will say "You have been playing for \V[1] seconds" when you poke on him.

6. Play test the game.

Play test result:

1. Game start.

2. Talk to the NPC. He will tell you that you have been playing for 5 seconds.

3. Wait 10 seconds.

4. Click on the switch event to trigger the "delay" switch ON.

5. Go talk to the NPC. In my case the NPC told me that I have been playing for 16 - 19 seconds instead of 6-9 seconds, which means: $game_variables[1] = $game_system.playtime - 10 doesn't work....

Possible problem:

$game_variables[1] = $game_system.playtime is okay because they are both using the STRING ("$").

$game_variables[1] = 0 is okay because in term of gaming world, "0" could be assumed as STRING and other conditional branches or switches or triggers will still work even if "0" (or any other numbers) is not INTEGER.

$game_variables[1] = $game_system.playtime - 1800 is not okay because STRING can not be subbed or added by INTEGER, it is like : "TWO + 2" it won't come out 4.....

That's what I thought btw.

Tell me if I get something wrong somewhere.....
 
Last edited by a moderator:

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
Hi, sorry that you're having some trouble.

 

Referring to your test event, at number '5', try placing a "Wait" event command with at least 2 frames, followed by your text.

I tested the script call with the switch at "ON" and "OFF".

The text will show a negative number if the variable is less then zero.

 

Please let me know if you're still having any problems.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Here's what I did to test:

1) Created a new, clean project

2) Created an NPC Action Event with the following event commands

  • Script: $game_variables[129] = $game_system.playtime
    $game_variables[130] = $game_system.playtime - 1800
  • Message: Time now: \V[129]
    Time - 30 min: \V[130]
3) Playtested; talked to that event and got the correct numbers (4 and -1796, etc.)

If you're having problems with line breaks (and I think you might be, given that the "-10" part seems to have been ignored in your example), you have a couple different options:

  • Work in a text editor that provides longer lines.  The Steam version of VX Ace also provides much longer text entry for events' Script lines.
  • Create the method in the Script Editor, where line size is unlimited.  So for example you'd create a new method in Game_Party called get_my_time that sets the variables to the desired amounts, then simply call that method using (watch the capitalization) $game_party.get_my_time
  • Do your assignment in steps.  For example, the first line would say a = $game_system.playtime and the second would say $game_variables[1] = a
Also, I don't understand what the point of your Parallel Process event is.  Why not just have the NPC's event code set the variable right before you need it, instead of having the game constantly use processing power to keep setting and resetting the variable?
 

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
@Wavelength :

- Your method worked flawlessly. I guess there was slight delay for me when using the common event. I'd turned the switch on and directly showed the variable, therefore needing a 'wait' command.

- I'm using VX Ace from the main store but my Script box seem to have a lot space to spare.

- Also, he did mention why he is using a parallel process common event and I can think of at least one other reason why he'd use in a case like this but I'll let him answer the question himself.

@metronome :

- Maybe it's time to request a screenshot showing the event process of your common event, as well as the actual Script box wherein you wrote your script call?
 

metronome

Veteran
Veteran
Joined
Aug 21, 2014
Messages
338
Reaction score
144
First Language
English (Sure!)
Primarily Uses
Here's what I did to test:

1) Created a new, clean project

2) Created an NPC Action Event with the following event commands

  • Script: $game_variables[129] = $game_system.playtime$game_variables[130] = $game_system.playtime - 1800
  • Message: Time now: \V[129]Time - 30 min: \V[130]
3) Playtested; talked to that event and got the correct numbers (4 and -1796, etc.)

If you're having problems with line breaks (and I think you might be, given that the "-10" part seems to have been ignored in your example), you have a couple different options:

  • Work in a text editor that provides longer lines.  The Steam version of VX Ace also provides much longer text entry for events' Script lines.
  • Create the method in the Script Editor, where line size is unlimited.  So for example you'd create a new method in Game_Party called get_my_time that sets the variables to the desired amounts, then simply call that method using (watch the capitalization) $game_party.get_my_time
  • Do your assignment in steps.  For example, the first line would say a = $game_system.playtime and the second would say $game_variables[1] = a
Also, I don't understand what the point of your Parallel Process event is.  Why not just have the NPC's event code set the variable right before you need it, instead of having the game constantly use processing power to keep setting and resetting the variable?
Hi,

Out of those 3 options, I chose the simplest one, the third option, in which I assigned "a" to $game_system.playtime and it works great!

The line break issue is really the problem I was having there~~

I didn't even know that you could do assignment step in this kind of scripting environment

Thanks a lot man.

About the point of the parallel process I will also answer Susan's quotes below:

@Wavelength :

- Your method worked flawlessly. I guess there was slight delay for me when using the common event. I'd turned the switch on and directly showed the variable, therefore needing a 'wait' command.

- I'm using VX Ace from the main store but my Script box seem to have a lot space to spare.

- Also, he did mention why he is using a parallel process common event and I can think of at least one other reason why he'd use in a case like this but I'll let him answer the question himself.

@metronome :

- Maybe it's time to request a screenshot showing the event process of your common event, as well as the actual Script box wherein you wrote your script call?
One of the reason I am using that parallel process common event for this is because I can't fine any simpler way to spawn NPC using "Play Time" as conditions.....

If only I can create an event, and then set "Play Time" >= 3600 (instead of "Variable[n] >= 3600") directly, then I wouldn't have this problem >.<

The next reason is: I want this parallel process to happen in every maps I have in that game. It would have been easier if all I want is "X enemies/events spawn @Y seconds of gameplay time", but this "delay spawns when you do something" makes it a bit more complicated since I already use parallel process for that Variable; meaning that I can't just create an event that will set that same Variable to other numbers, since the parallel process will just change that number in the next frame.

@Susan

seems like I will disappoint you for the reasons I really have for using a parallel process common event are simple ones LOL. but I think this will be useful for anyone who wants to create something that relies on gameplay time and do something to delay/fast forward one or more events to spawn~~.

Thanks for your helps guys~
 

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
No reason to be disappointed here, I wasn't thinking of anything complicated. Lots of people use parallel process common events for very simple reasons. Myself included. I'm just glad you found your answer.

I've been meaning to tell you that it is possible create respawnable enemies based on gameplay time. It needs to be differently though. Do come around again when you need something, or even just for fun.

Happy eventing!
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Hi,

Out of those 3 options, I chose the simplest one, the third option, in which I assigned "a" to $game_system.playtime and it works great!

The line break issue is really the problem I was having there~~

I didn't even know that you could do assignment step in this kind of scripting environment

Thanks a lot man.
Glad we got it working for ya :)

RGSS3 is a library built on top of Ruby, so you can do almost anything you'd do in the Ruby language, and more!

One of the reason I am using that parallel process common event for this is because I can't fine any simpler way to spawn NPC using "Play Time" as conditions.....If only I can create an event, and then set "Play Time" >= 3600 (instead of "Variable[n] >= 3600") directly, then I wouldn't have this problem >.<

The next reason is: I want this parallel process to happen in every maps I have in that game. It would have been easier if all I want is "X enemies/events spawn @Y seconds of gameplay time", but this "delay spawns when you do something" makes it a bit more complicated since I already use parallel process for that Variable; meaning that I can't just create an event that will set that same Variable to other numbers, since the parallel process will just change that number in the next frame.
Sure, that makes sense.  Since you're working on large time scales, be sure to add a reasonable Wait time at the end of the parallel process event (I'd say 30 or 60 frames) to avoid committing too many system resources to this event.  In the event body, simply update the variable to the total playtime (in seconds), run the conditional branch against the variable, and have the enemy spawn if appropriate.

You could also consider using Hime's "Custom Page Conditions" script to directly determine whether an event should show up or not.  It's an excellent script.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top