Author Topic: When to use repeat count and/or trigger count?  (Read 2024 times)

0 Members and 1 Guest are viewing this topic.

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
When to use repeat count and/or trigger count?
Been wondering what the differences are and when to use trigger count instead of repeat count.  Also if they need to be used together or when they can be used together.
No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras

 

Offline Scotty

  • 1.21 gigawatts!
  • 211
  • Guns, guns, guns.
Re: When to use repeat count and/or trigger count?
I think the difference is that the trigger count is how often the event as a whole can be repeated, while the repeat count is how many times the result of the event is repeated. 

For example, say you have Ship A slated to say the same thing every time an enemy wing jumps in.  You would set the trigger count to how many wings will come in.  However, if you were to set the repeat count to how many wings jump in, you would get the result of having Ship A say the same thing in succession that many times.

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: When to use repeat count and/or trigger count?
Trigger count exists because repeat count doesn't do what a lot of people think it does.



Quick explanation

Repeat Count - When a repeat count is set the repeat delay is the time when the event will next be tested. A repeat delay of 10s means that the event will be tested at 10, 20, 30, 40.....  seconds after the first time the SEXP is triggered.

Trigger count - When a trigger count is set the game waits the repeat delay and then sets the event back to being checked every frame until it is triggered again, when it waits the repeat delay again.



Longer explanation

I'll give an example of a SEXP and how you'd solve the problem in the past (using repeat count) and how you can solve it now using trigger count (or both).

Let's suppose I have a target ship in a mission. If Alpha 1 is less that 100m from the ship I want a message sent every 10 seconds.
I set up this event.

Quote
Player near Target [repeat count = 9999999, trigger count = 1 (default), repeat delay = 10]
when
- <
--distance
---Alpha 1
---Target
--100
-Send Message


That probably seems reasonable but if you ran it you'd find it didn't work. What would happen with this event is that the player triggers the event after 5 seconds the first time by flying into range. 10 seconds later the game checks if the player is in range again. If he is, another message is sent. Regardless of whether the message is sent or not the game now waits another 10 seconds to test again. In other words if the player flies within range 13 seconds later and back out again 19 seconds later they'll miss the test 20 seconds after the SEXP triggered and won't get the message sent.

In the past the solution was something like this.

Quote
Player near Target [repeat count = 9999999, trigger count = 1 (default), repeat delay = 1]
when
-and
- =
-- OkToSendMessage[1]
-- 1
-- <
---distance
----Alpha 1
----Target
---100
-modify-variable
--OkToSendMessage[1]
--0
-modify-variable
--MessageSent[0]
--mission-time
-Send Message


Reset Message[repeat count = 9999999, trigger count = 1 (default), repeat delay = 1]
when
-=
--MessageSent[0]
-- +
---mission-time
---10
-modify-variable
--OkToSendMessage[1]
--1

Basically repeat count is simply being used to make the game check the event every second and the FREDder has to manually tell it to wait 10 seconds before checking by using a combination of variables to manually add the initial 10 second delay. But why should the FREDder have to tell the game to wait 10 seconds Wouldn't it be nice if we could get the game to do all that for us instead? That's what trigger count does. It tells the game wait the amount of time specified in the repeat delay and then trigger normally. Here's the same event using trigger count.

Quote
Player near Target [repeat count = 1(default), trigger count = 9999999, repeat delay = 10]
when
- <
--distance
---Alpha 1
---Target
--100
-Send Message

Notice how that is exactly the same as the original event except that I've swapped the trigger count and repeat count around? Trigger count works in the way many people think repeat count works.


As for using both together, yes you can but it's really just a side effect of the way both work rather than a deliberately designed feature. Suppose we have a situation where you do want to check only every 10 seconds and want to stop sending messages after 3 have been sent regardless of how long it takes to get those three. Well in that case, you can either use a variable as a counter or you can do this.

Quote
Player near Target [repeat count = 9999999, trigger count = 3 (default), repeat delay = 10]
when
- <
--distance
---Alpha 1
---Target
--100
-Send Message

When both are specified the repeat count takes precedence. The game will test at 10 second spaces. But due to the fact that the game decrements both counts every time the event triggers you can use the trigger count as a built-in countdown counter for how many times the event has triggered. As soon as it reaches 0 the game won't trigger the event any more, regardless of what the repeat counter is.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Black Wolf

  • Twisted Infinities
  • 212
  • Hey! You! Get off-a my cloud!
    • Visit the TI homepage!
Re: When to use repeat count and/or trigger count?
Beautiful explanation. :D Wiki'd.
TWISTED INFINITIES · SECTORGAME· FRONTLINES
Rarely Updated P3D.
Burn the heretic who killed F2S! Burn him, burn him!!- GalEmp