Home   Help Search Login Register  

Author Topic: publicvariable in MP  (Read 1269 times)

0 Members and 1 Guest are viewing this topic.

Mr.BoDean

  • Guest
publicvariable in MP
« on: 07 Jul 2004, 22:18:33 »
Ok, I've been reading thru a lot of posts on this subject.
 Is the simple answer that whenever you're using global variables in any script , server-only or client and server, that you should just announce it to all with publicvariable??
  ???

Is there any harm to doing so? Because I just am not 100% clear when I need it or don't.  :P  :-X

Offline CrashDome

  • Members
  • *
Re:publicvariable in MP
« Reply #1 on: 07 Jul 2004, 23:59:07 »
Global variables are actually copies on all machines at the time they were created (In an init line or init.sqs file for example)

If a script runs on only one machine, then that machine changes the value of that copy. The others will not see the change and therefore need to use publicvariable to notify of change.

Example:
Create test mission and place a game logic and call it "server"

Init.sqs
Code: [Select]
myVar = 10
;This is run at beginning of mission by all machines so all machines have a value of 10

? (local server) : myVar = 12
;game logics are local only on the server so when all machines reach this point, then only the server will execute the change in value

? (local server): publicVariable "myVar"
;Again only the server will execute this and broadcast it's value to the other machines
;You cannot have all machines broadcast the value at the same time or you will
;not guarantee who gets what value as there will be multiple values flying back and forth
;At the end of this script, all machines should have myVar = 12 because of publicVariable command.
;To test, comment this line out and see what happens



Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:publicvariable in MP
« Reply #2 on: 08 Jul 2004, 01:11:43 »
what you have to think about is

Does every machine need to know the value for "myvar" when it changes

If yes, then use a publicvariable
Example (Westscore)
(Server scoring system)
 
Quote
Westscore = westcore + 1; Publicvariable "Westscore"

If NO, ask yourself
Does anymore scripts on the local machine need to know the value for Myvar when it changes

If yes use a global variable (available to all scripts on the same machine)
Example (IamLeader)
 
Quote
?(Player == W1): Iamleader = true
?(IamLeader): [] exec "Leaderactions.sqs"

If no, then use a local variable
Example (_count)
Quote
_count = 0
#START
~1
_count = +count + 1
?(_count >= 20): goto "NEXT"
goto "START"

#NEXT
hint "Time up"


Points to note

You cannot transmit
a) Strings eg........ "My name is Arthur"
b) Arrays  eg..........Playerarray = [W1,W2,W3,W4,W5]
using publicvariables

COC has a system that enables you to do this and there are ways of working around this using standard BIS commands
« Last Edit: 08 Jul 2004, 01:26:15 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Mr.BoDean

  • Guest
Re:publicvariable in MP
« Reply #3 on: 08 Jul 2004, 04:00:13 »
Thanks for the help, Terox. Ok, in my mission, I am specifically using only true/false (boolean) global variables to either trigger other scripts or satisfy triggers.

Most of these events involve enemy AI (this is a coop mission) and their vehicle's movements.The helimove script is run on server only.

Move script:
Code: [Select]
;; Heli cycling script by Mr.BoDean
;; Requires placing GL's named server,helimove1,helimove2,etc. on map

_heli = _this select 0
Hold = false
_heli setbehaviour "Careless"

?!(local server) : exit

_heli move getpos helimove1
~85

#Moveloop
? Hold : goto "Holdpat"
_heli move getpos helimove1
~28
_heli move getpos helimove2
~38
? Hold : goto "Holdpat"
_heli move getpos helimove3
~33
_heli move getpos helimove4
~33
goto "Moveloop"

#Holdpat
_heli move getpos helimove5
~25
#HoldCond
;;;;? !Hold && (helimove5 distance Mi17 < 300): _heli setpos GetMarkerPos "MI17M"
? !Hold: goto "Moveloop"
~3
goto "HoldCond"

That script is fed the global variable from a createunit/paradrop script after conditions are met.

? ("alive _x" count units paragroupF == 0): goto "waitcount"

#waitcount
Papabear sidechat "blah,blah!"
~1
Hold = false
_counter = _counter +1
goto "loop"


The createunit/ para script is executed from a trigger by the corresponding AI heli. Only the createunit lines are isolated with

?(local server) : "SoldierEB" createunit ..............
 

A couple scripts do involve events which (could) happen to (empty) vehicles operated by players. Those in particular make me wonder how to run them. I figured because they affect players directly, they need to run on all?

FuelLeak.sqs:

Code: [Select]
;Fuel leak Script by Mr.BoDean & others

_flag1=false

#Leak
AH6 setFuel ( Fuel AH6 -.04)
? Fuel AH6 == 0 : exit
? Fuel AH6 <= 0.8 and !_flag1: goto "CHAT"
~0.5
goto "Leak"

#CHAT
P1 GroupChat "OH CRAP! LOOKS LIKE A FUEL TANK LEAK...."
_flag1=true
goto "Leak"


Thanks again for the help.  ;)