Home   Help Search Login Register  

Author Topic: Enough time for publicVariable???  (Read 3745 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Enough time for publicVariable???
« on: 26 Jun 2009, 01:30:20 »
Hi all,

Working on a dog tracking script and YES I know .sqs is obsolete, but this script is so simple it won't matter and I always start by making my scripts in .sqs before implementing them in .sqf anyway  >:(

What I'm worried about is if the unit name "trackDog1" will be recognized by all clients and thus making everyone hear the barking effect.

The script works through the init field of a unit that is deleted and replaced by a dog. The script is called by: [this] exec "dogtrackingparty.sqs", which looks like this:

Code: [Select]
_dummy = _this select 0
_trackers = group _dummy
deleteVehicle _dummy
~ 1

? isServer : trackDog1 = _trackers createUnit ["Pastor", position leader _trackers, [], 0, "FORM"]; publicVariable "trackDog1"
[trackDog1] join grpNull
trackDog1 joinAs [_trackers, 2]
~ 1

trackDog1 setskill 1
trackDog1 setSpeedMode "FULL"
trackDog1 allowFleeing 0
~ 1

[trackDog1] exec "dogBark.sqs"


? ! isServer : exit

#choice

_preyNum =  count preyList
_preyChoice = floor random _preyNum
_chosenPrey = preyList select _preyChoice


#trackloop

? ! (alive trackDog1) : exit
_trackers move getpos _chosenPrey

@ unitReady leader _trackers

if (! (alive _chosenPrey)) then {goto "choice"} else {goto "trackloop"}

The: [trackDog1] exec "dogBark.sqs" must be recognized by all clients... Will it be?

Thanks in advance... and please no jokes about .sqs  :-[

Laggy
« Last Edit: 26 Jun 2009, 01:38:13 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
Re: Enough time for publicVariable???
« Reply #1 on: 26 Jun 2009, 11:13:59 »
i'd put a
Code: [Select]
waitUntil { !isNil {trackDog1} };
before you start using the trackDog1 variable after the isServer thing, so the clients won't execute anything with an undefined variable (which arma2 now creates an error report for in the rpt-file).

I have no idea how to write that in sqs though (sqs is so 2003  ;))
« Last Edit: 26 Jun 2009, 11:17:12 by mikey »

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Enough time for publicVariable???
« Reply #2 on: 26 Jun 2009, 14:41:40 »
.sqs  ;)
Code: [Select]
@ ! isNil trackDog1
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Enough time for publicVariable???
« Reply #3 on: 26 Jun 2009, 21:50:51 »
Mikey, your code is so 2006 and would only work in A1; it would cause an error is A2 :D. The other thing is to remember to quote the name of the variable rather than give it, just like with publicVariable.
Code: (sqf) [Select]
waitUntil { !isNil "trackDog1" };
Code: (sqs) [Select]
@ !isNil "trackDog1"

But seriously, if you want to check a variable, always use the "" version:
Code: [Select]
isNil "trackDog1";
The alternative bracketed form should only be used for "derived" values, such as array elements or variables on things:
Code: [Select]
isNil { array select 5 }; // Where you are sure that 'frog' is defined, but not sure about 6th element.
isNil { obj getVariable "fish" }; // Where you know obj exists, but not sure about "fish" on it.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
Re: Enough time for publicVariable???
« Reply #4 on: 27 Jun 2009, 02:44:04 »
Mikey, your code is so 2006 and would only work in A1; it would cause an error is A2 :D.

You sure? cause i dont see any errors in the rpt, and I even saw it being used in the modules.

But ok, when using variable names, pass it as a string if you wanna be hip and contemporary :)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Enough time for publicVariable???
« Reply #5 on: 27 Jun 2009, 20:01:26 »
Yes, this is a key change in Arma 2. That is, that you now get error reports when you try to reference an undefined variable. There are situations, though, where Arma suppresses the error messages (from even RPT) which is very annoying.

Just because a random BIS contractor did something in a module, doesn't mean they know what they are doing any more than the community member they were before they signed a contract (though generally they do ;)).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Enough time for publicVariable???
« Reply #6 on: 29 Jun 2009, 09:27:47 »
Thanks all  :D
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.