Home   Help Search Login Register  

Author Topic: snYpir's MP tute & publicVar  (Read 1583 times)

0 Members and 1 Guest are viewing this topic.

Rubble_Maker

  • Guest
snYpir's MP tute & publicVar
« on: 23 Feb 2003, 11:17:13 »
Hi

I was reading snYpir's MP tute and I noticed that he suggests calling "publicVariable" whenever a variable is changed somewhere. In the OCR however it sounds like you only have to call it once, and then the OFP engine will automatically broadcast the variable to all computers during the session. I've seen ppl do it both ways in their missions, and both seem to work, so I'm a bit confused now ;)  Can someone plz enlighten me as to
wether or not there's any difference?

Oh, and another q:

?(local SERVER): bla (serverstuff)

works nicely when there's actually a SERVER unit on the map. It'd be cooler tho to have the script create the logic itself:

_server= "logic" camcreate [0,0,0]
?(local _server): bla (serverstuff)

Does this work? I want to make 3 sqf functions which you can use to easily detect if you're on a server, client or dedicated server; I will post them here if the above trick works.

Tactician

  • Guest
Re:snYpir's MP tute & publicVar
« Reply #1 on: 23 Feb 2003, 12:46:39 »
A boolean (true or false) variable can be safely publicVariabled by all clients, and it's probably safer to do so in most cases.  The only time I've run into that you shouldn't have all players publicVariable something is when incrementing a variable (i.e. WScore = WScore + 1; publicVariable "WScore") because each client will increment it, even after receiving the incremented score, so it becomes a big mess.

Apart from these examples, you really have to decide how to use publicVariable on a case-by-case basis.

As for creating server-logic dynamically, that's good for keeping your scripts portable, but is slightly less efficient than using one static game logic.

Rubble_Maker

  • Guest
Re:snYpir's MP tute & publicVar
« Reply #2 on: 23 Feb 2003, 16:18:16 »
Ok so "publicVariable" accomplishes the actual broadcasting right? The way I understood it just tells the OFP engine which variables should be send from server to clients with each frame, in which case it'd have been totally sufficient to call "publicVariable" only once for ever variable.

Well then you're right, you shouldn't have multiple scripts incrementing the same vaiable coz their results will partially overwrite.

anyways thx

btw do I have to camcreate or createVehicle the SERVER logic?

Offline Yakuzi

  • Members
  • *
Re:snYpir's MP tute & publicVar
« Reply #3 on: 20 Mar 2003, 21:23:14 »

btw do I have to camcreate or createVehicle the SERVER logic?

The only thing ya have to do is create a Game Logic in the editor and name it Server. If I'm correct Game Logics will only show up on the Servers so if they can detect the game logic it will now its the Server  :o
BTW Game logics are under "units->game logic".
I taught your girlfriend that thing you like...

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:snYpir's MP tute & publicVar
« Reply #4 on: 21 Mar 2003, 00:39:33 »
PublicVariable:
PublicVariable tells the local machine to transmit that value to all machines at that moment.

It does not mean that the values are synchronized between all clients.

So if you want to synchronize your updates, have every update followed by a publicvariable.
Dinger/Cfit