Author Topic: Campaign persistant variables and every-time sexp  (Read 4791 times)

0 Members and 1 Guest are viewing this topic.

Offline ReeNoiP

  • 27
  • I FRED
Campaign persistant variables and every-time sexp
I am trying to make a freigther-destroyed count using the every-time sexp and a variable like this:

Code: [Select]
every-time
 -or
  --is-destroyed-delay
   ---freigther 1
   ---0
  --or
   ---is-destroyed-delay
    ----freigther 2
    ----0
   ---is-destroyed-delay
    ----freigther 3
    ----0
 -modify-variable
 --freigther-count(0)
  --+
   ---freigther-count(0)
   ---1

But when I check the variable after destroying say 2 freigthers in the debriefing it reads it as 0. If I use "when" instead of "every-time" it can only count to 1. Do I need to create an event for the destruction of each freigther or can this be fixed somehow?

I plan to use this as a campaign persistant variable. When the time comes to call it in another mission, is there a clever way to do some testing with different values without completing the first mission again?
Uncharted Territory is released. But I still need voice actors

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Campaign persistant variables and every-time sexp
Well first there is no reason to use every-time for something like that.  Every-time should only be used in special circumstances.  A repeating when would work just fine for something like you are trying.  This would be even easier:

when-argument
--any-of
---freighter 1
---freighter 2
---freighter 3
--is-destroyed-delay
---<argument>
--modify variable
---freighter count
----+
------freighter count
------1
--invalidate argument
---<argument>

Just give it a repeat count of at least 3.  



Note I didn't actually test that but it should work.
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Campaign persistant variables and every-time sexp
Actually give it a much higher repeat count than 3. Repeat count is how often the event will be tested following the first triggering. It is not how many times the event will trigger.

That's actually one of the biggest misconceptions out there. :D

And yes, I'm thinking of adding a setting that actually does count how many times an event should trigger.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Campaign persistant variables and every-time sexp
I always set them to 999999999.  Mission goes longer then that then your on your own.
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Campaign persistant variables and every-time sexp
Okay, took a look at the code and I implemented a new Trigger Count setting that does what most people thought Repeat Count was doing all along. :D

It works like this. Suppose I have this event.

Player near Target
when
- <
--distance
---Alpha 1
---Target
--100
-Send Message

If you define a Repeat Count of 4 and an repeat delay of 10 the game will wait until you get closer that 100m from the target. Let's say you do that 5 seconds in to the mission. The game will check again if you are 100m from the target at t=15 second, 25 seconds and 35 seconds (remember that a repeat count of 1 = no repeats. Another oddity of the way this feature works).  If you are 80m from the target at 20 seconds but manage to be 100m away at 15 and 25 seconds you won't see any message.

On the other hand, if you define a Trigger Count of 4 and an repeat delay of 10 the game will wait until you get closer that 100m from the target and send the first message. It will then wait 10 seconds and begin to test again every frame until you come closer than 100m again. It will do this until 4 messages have been sent (including the original one). As with Repeat Count, a Trigger Count of 1 means no repeats (it literally means trigger once and then never again).

Finally you can define both. If you define a Repeat Count of 4, a Trigger Count of 2 and an repeat delay of 10 the game will wait until you get closer that 100m from the target. Let's say you do that 5 seconds in to the mission. The game will check again if you are 100m from the target at t=15 second, 25 seconds and 35 seconds until another message is sent. After 35s it will not check again even if the second message has not been sent.

I'll be adding this to the 3.6.11 codebase as soon as I've coded in the FRED changes to support it (tomorrow most likely) and I recommend that we simply start telling people to use it instead of the much more confusing repeat count. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Qent

  • 29
Re: Campaign persistant variables and every-time sexp
Well first there is no reason to use every-time for something like that.  Every-time should only be used in special circumstances.
What is wrong with every-time in this instance?

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Campaign persistant variables and every-time sexp
Every-time does not do what most people think it does. Most people use every-time in order to make an event repeat every frame. It will do this but so will using when with a repeat/trigger count and a repeat delay of 0.

What every-time will also do however is flush the entire SEXP clean every frame and re-test everything. And in 99% of the cases where it is used, this isn't what you want. Internally SEXPs work in a quite interesting way. Suppose I have an event like this

when
-or
--has-departed-delay
---ship 1
--has-arrived-delay
---ship 2

If ship 1 is destroyed the departed SEXP will be marked SEXP_KNOWN_FALSE and never will get tested again. Why should it? The game knows that with the ship destroyed it can never ever depart so why waste CPU cycles checking it again? Every-time on the other hand will force the game to check if the ship that has been destroyed has departed every single frame. For no good reason.

Fortunately, the game checks SEXPs quite quickly so there isn't much of a problem caused by checking the SEXPs again. But why needlessly waste CPU time? :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Campaign persistant variables and every-time sexp
You should just stick that speech Kara.
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Campaign persistant variables and every-time sexp
To be honest it's only of minor importance really. Nothing much will go wrong from using every-time instead of a repeating when and it does have a slight readability advantage in that it makes it obvious without looking at the repeat count what you want it to do.

It's just that it's a bit of a waste and it does mean you can't use chains or is-event-true-delay with the SEXP any more.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Snail

  • SC 5
  • 214
  • Posts: ☂
Re: Campaign persistant variables and every-time sexp
Maybe someone could Wikify this... Maybe then people wouldn't get so confused...

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Campaign persistant variables and every-time sexp
You mean like this?

 

Offline ReeNoiP

  • 27
  • I FRED
Re: Campaign persistant variables and every-time sexp
Thanks for the help on the sexp. I got it working with "when-argument".
Uncharted Territory is released. But I still need voice actors

 

Offline ReeNoiP

  • 27
  • I FRED
Re: Campaign persistant variables and every-time sexp
OK, I am about to use the campaign persistant variables in a later mission (1 in between if that matters), but I am not sure how to call it. Basically, what I want to do is have a cruiser arrive if the sum of the variables is less than 4, but if I add a variable with the same name, I have to input an initial value. Will this overwrite the value which was saved in the campaign file earlier?
 
Uncharted Territory is released. But I still need voice actors

  

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Campaign persistant variables and every-time sexp
The value saved in the campaign file will take precedence over the initial value.