Author Topic: Persistant varibles in multiplayer?  (Read 2061 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
Persistant varibles in multiplayer?
I've been avoiding them just because I'm trying to stay retail compatible.  I started thinking about them thought.  What would happen if they were used in a multiplayer campaign?  With people dropping and that ingame joining stuff would there be problems?  What if you played a mission that is in the campaign then started the whole campaign?  Is it just going to handle them on the server side?
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: Persistant varibles in multiplayer?
Right. All variables only work on the host in retail. There is no mechanism for sending them to the client and in retail this doesn't matter much cause there's pretty much bugger all the client could do with them even if they were sent over there.

In 3.6.9 you now have network variables. Whenever you use the modify-variable SEXP the game will check if the variable is a network variable or not. If it is then it will send it to the clients regardless of it's persistence. This does mean that you can cause lag by continuously sending lots of network variables to everyone so use them sparingly.

When someone does an ingame join they'll receive the value of the persistent variable in the mission file not it's current value. That means that they'll have the wrong value for the variable until the variable is modified. The only real use for client side variables is in messages though so that isn't a problem as long as you update the variable before any message using it is sent.
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: Persistant varibles in multiplayer?
I was thinking more along the lines of thier use in a multi-player campaign.   I saw your post about using them in the realistic campaigns thread and was thinking what that would do in multi. 

I've already written a campaign where there is a bonus mission to caputer a ship.  If you capture it the campaign  branches one direction if not or you don't get the bonus mission then it goes another.  When I did it I just copied the mission and made the changes.  Since I never finished the campaign I was thinking of using variables and eliminating the near duplicate missions.  It would make it easier for testing since I could set the variable instead of playing the campaign.  I think that was the only reason I made 4 missions instead of 2.  Got to love going back and looking at stuff thats over 5 years old and trying to figure out what the heck you did that for.
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: Persistant varibles in multiplayer?
That would work perfectly with persistent variables as only the host would ever need to know the real value of the variable.
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: Persistant varibles in multiplayer?
Just checked the Wiki on PVs and am still confused on using them this way.  Got a quick example or a link to a better description? 

One other thing I'm trying to figure out with this is if there is any way to tell if the mission is being played as part of the campaign or just by itself.   I'm sure I could rig it for the second mission and those following but the first one is a bit more complicated.  I'd like to have some of the briefing stages come up only if it's being played as part of the campaign.   
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: Persistant varibles in multiplayer?
Just checked the Wiki on PVs and am still confused on using them this way.  Got a quick example or a link to a better description?


Here's what I have on them in my FAQ.

Quote
What is a persistent variable?

Standard variables can only be used in the mission they appear in. At the end of the mission FS2 cleans up by wiping the variable completely.
Persistent variables on the other hand are recorded in the campaign file (or pilot file). As a result once you have declared a persistent variable you can use it in any later point in the campaign where it will remember the value it was set to earlier.
There are actually two kinds of persistent variables. Campaign Specific and Player Specific depending on where they are saved. The way they work is subtly different.

The player specific variable is actually the simpler one of the two. Suppose in mission 2 of a campaign I set a player specific variable to 5. On loading mission 7 of the campaign the variable will still equal 5. Suppose I now set the value to 10. Shortly after this (while still in mission 7) the player gets killed. This time when the mission starts the variable equals 10. In other words PS variables always equal whatever they were last set to.

The campaign specific variable works slightly differently. Taking the above example suppose in mission 2 of a campaign I set a player specific variable to 5. On loading mission 7 of the campaign the variable will still equal 5. Suppose I now set the value to 10. Shortly after this (while still in mission 7) the player gets killed again. On restarting the mission the variable is reset to 5 again. CS variables only permanently change when you move on to the next mission in the campaign. This makes them the more commonly used one of the two as persistent variables are generally used for recording hull percentages and other similar things which you don't wish to change should the mission require a restart.


Quote
One other thing I'm trying to figure out with this is if there is any way to tell if the mission is being played as part of the campaign or just by itself.   I'm sure I could rig it for the second mission and those following but the first one is a bit more complicated.  I'd like to have some of the briefing stages come up only if it's being played as part of the campaign.

Hmmmm. I'm trying to think of a way to do that in the first mission of a campaign. I have an idea. Let me go test it out first :) Is this for a multiplayer mission BTW? Cause do multiplayer campaign missions even show up on the singleplayer list?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Persistant varibles in multiplayer?
Okay. I got around to testing my idea and it does work (Only in HEAD builds due to the feature it's using).

Basically the only way I could think of was to do this.

1) Make the mission and select a class of ships for Alpha 1 that you don't particularly care if no one can fly in the campaign (The Herc is a fairly good choice but you might have a better alternative)
2) Make sure the Herc is available to you in the Team Loadout screen
3) For alpha 1 select the Set Class Dynamically in the Ships Editor -> Misc Properties dialog.
4) Make a campaign file but in the allowed ships do not include the Herc
5) In the briefing screen include this SEXP as the trigger for any briefing stages you want to appear only in the techroom

Code: [Select]
is-ship-class
Herc
Alpha 1

6) For any briefing stages you want to only appear in campaign mode simply invert the check to

Code: [Select]
not
is-ship-class
Herc
Alpha 1

You're probably not familiar with the improved team loadout functions in HEAD so I'll explain what's going on here. When you turn on the Set Class Dynamically option you turn on the new loadout code for the ship in question. The new loadout code then looks at every ship and assigns its class based on what is left in the loadout rather than just what class the ship has in the mission file.

In the Techroom (for SP) or as a standalone multiplayer mission the game will noticed that there are Hercs available in the loadout so the player is  given the ship you'd expect. In a campaign however the campaign file states that you cannot fly a Herc as you've not been granted permission to fly one and removes the ship from the loadout screen. Normally FS2 won't give a damn about this and will still give you a Herc as well but you've chosen to Set Class Dynamically so now when the game comes to assigning Alpha 1 a class it spots that this time there are no Hercs available and gives you the first ship it can find off the loadout list.

So now you have a situation where you're flying a Herc in the techroom or standalone multi but have something else in a campaign. You simply test what ship the player has by default and then you're fine (Don't worry. If you later change Alpha 1 from the Herc the whole thing doesn't fall apart).

Of course the real irony is that I could probably have made an is-campaign SEXP in the time it took to write all that. :p

To be honest I think I'll add one anyway. I had other reasons for testing what I did. :)
« Last Edit: February 05, 2007, 11:17:25 am by karajorma »
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: Persistant varibles in multiplayer?
Great so I can ignore that hole scenario and just use the sexp when it's available.   :D  Although that could give me a workaround to the next scenario I was going to ask about. 

What happens if a CS variable is referenced by a mission that isn't launched from the campaign file that defined it.  Is there a way to test if the variable exists and set it if it doesn't?  I guess what I am asking is can I (or do I even need to) do something like this:

When
-->not
---->is-campaign
-->define-variable
----><variable>
----><value>

So that the variable will exist for the mission when it is not played from the campaign.  Most people never played mult campaigns just the individual missions.   
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: Persistant varibles in multiplayer?
You're misunderstanding how Persistent Variables are declared in the first place. To use a persistent variable in two missions you simply declare two variables (one in each mission) as you would normally (with a name and default value) and then tick the persistence option you want.

The game then deals with the variable in campaign mode. It notices that in the second mission there is a persistent variable declared and looks back through the previous missions of the campaign to see if one with the same name exists. If it finds it, it throws away the default value and replaces it with the value the persistent variable had in the last mission. If it can't find it it regards it a new persistent variable.

In standalone mode the variable is no different to a standard variable. It's value will be whatever the default value for the variable is (Which is actually very useful as it means you can change the default value and play the mission standalone in order to test how the mission would work with different values for the persistent variable in campaign mode).

The important upshot of that is that you can not access a persistent variable in a mission which you have not declared it in. Until you declare if FRED has no idea that the variable even exists.
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: Persistant varibles in multiplayer?
OK now that makes sense.  I was reading it as if you declared it in the .fc2 file.  It should do exactally what I want  then.  If I declare the variable with a value of 0 in every mission and then set it to say the mission # at the end of the mission I can tell what router the campaign has taken or force the variable for testing.  This along with that is-campaign sexp should wipe out 2 missions from my list of things to do. 

Of course on the downside I can't use them until the rewrite but I'm making notes for FS2_open changes as I go.   I can still probably eliminate the 2 missions.  Retail just would get the capture failed route if played outside the campaign.   Well I've got 12 missions to test and fix before I get there so there's time to think about it. 
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