Home   Help Search Login Register  

Author Topic: a couple of questions on public variables  (Read 2301 times)

0 Members and 1 Guest are viewing this topic.

Offline FiLL2d

  • Members
  • *
  • X.x
a couple of questions on public variables
« on: 22 Aug 2006, 03:37:30 »
can someone help me with a couple of questions on public variables.

1. Making a public variable transmits the variable's value amongst all machines, although if the variable changes, is the change transmitted to all the machines or must the variable be changed to public again for the changes to be recongized by everyone.

2. Does a loop making a variable public continously continue to build up data in the memory or does it overwrite/ignore it


thx in advance

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: a couple of questions on public variables
« Reply #1 on: 22 Aug 2006, 07:23:57 »
1: Public variable is not a type of variable, it is a command to make global variable public. If you got a global variable on one client that you wish to transfer to other clients, you PV it. When you change the information in the global variable, you have to PV it for other client to get the information. That is, unless the global variable is set to the same on all clients.

2: I'd think it overwrites...


Sorry for any unclear answers...it's early in the morning and I've gotta go so I don't miss my bus to the uni :zzz:

SyB

  • Guest
Re: a couple of questions on public variables
« Reply #2 on: 22 Aug 2006, 13:09:03 »
Hi there,

Think of the 'PublicVariable' command as more like a 'Broadcast' or 'Publicize' this global variable value to all computers type of command.

The one rule you should observe (in my opinion) is... "Only ever have 1 computer modifying and 'Broadcasting' the particular global variable" AND preferably (but not restricted) have this done on the server/host computer.

Clear as mud?  :dry:,  :afro:

Cheers

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: a couple of questions on public variables
« Reply #3 on: 22 Aug 2006, 16:37:41 »
Additional Info

Publicvariable will not transmit
a) Strings:
eg "This is a string"
b) arrays:
eg   Tx_MyArray = [1,2,3.5,4.2]


to broadcast these across a network
You either
Transmit a number from machineA to machineB and have a script waiting for that number to be transmitted then compare it and select a string variable from it


eg

MachineA
Quote
tx_String = 1; Publicvariable "Tx_String"

MachineB
Quote
#START
@ tx_string > 0
?(tx_string == 1): Tx_Message = "hello"
?(tx_string == 2): Tx_Message  = "Goodbye"
hint tx_message"
tx_string = 0
goto "START"


or if you want to transmit dynamically created arrays or strings then you need to use CoC_Ns



and to transmit multiple publicvariables in one pass use

Tx_A= Etank
Tx_B = getpos (ETank select 0)
Tx_C = getpos (ETank select 1)
{publicvariable _x} foreach ["Tx_A",Tx_B","Tx_C"]
« Last Edit: 22 Aug 2006, 16:42:12 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: a couple of questions on public variables
« Reply #4 on: 22 Aug 2006, 19:17:39 »
Few other comments on publicVariable.

1) It is a good practice to initialise any variables you intend to publicVariable in your init.sqs, even if you just assign them dummy values.

2) You can only  publicVariable global variables i.e. variables without a leading underscore in their names.

3) The publicVariable command can be unreliable, especially when called near the beginning of a mission, or from the init.sqs, and extra especially if the network connections are laggy.  I have gotten in the habit of double pv'ing variables when near the start of a mission.
« Last Edit: 22 Aug 2006, 19:19:10 by Mr.Peanut »
urp!

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re: a couple of questions on public variables
« Reply #5 on: 05 Sep 2006, 11:54:42 »
Few other comments on publicVariable.3) The publicVariable command can be unreliable, especially when called near the beginning of a mission, or from the init.sqs, and extra especially if the network connections are laggy.  I have gotten in the habit of double pv'ing variables when near the start of a mission.
People who use publicVariable in parts of the init.sqs that runs on every machine anyways, always, should be strung up in the nearest tree. 

(Obviously, if one has a init.sqs that's written so as to only execute on one machine, publicVariable use again becomes relevant.)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: a couple of questions on public variables
« Reply #6 on: 05 Sep 2006, 12:16:02 »
Quote
People who use publicVariable in parts of the init.sqs that runs on every machine anyways, always, should be strung up in the nearest tree. 
:D :D
Read: "Don't use pV in init.sqs"


Wait, is there a nearestTree in OFP?  :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: a couple of questions on public variables
« Reply #7 on: 05 Sep 2006, 18:15:21 »
Some people have used PV in the init.sqs for MP broadcasting of random numbers needed near the mission start. This is not recommended.  If you need to use PV near the mission start, put in a script with a non-zero pause at the top, and call the script from the init.sqs.  A pause must wait until the mission starts.  I had a lot of problems with a simple script that was to generate a random mission start time (which can also be done using by specifying a random number as a possible param in the description.ext but that is beside the point).  The only solution was this:
Code: [Select]
publicVariable "myNumber"
~random 0.1
publicVariable "myNumber"
~random 0.1
publicVariable "myNumber"
~random 0.1

One other thing. If you have multiple variables to PV at the same time do this:
Code: [Select]
{publicVariable "_x"} forEach [x1, x2, x3 .....] to help prevent lag.
urp!