Home   Help Search Login Register  

Author Topic: confused  (Read 704 times)

0 Members and 1 Guest are viewing this topic.

Pravit

  • Guest
confused
« on: 28 Dec 2003, 23:40:45 »
_captain = _this select 0
_car = _this select 1
_truckguys = group _captain

Why is it that
_captain moveindriver _car
will work fine, but

"_x moveincargo _car" foreach units _truckguys
doesn't?

Offline rhysduk

  • Former Staff
  • ****
Re:confused
« Reply #1 on: 29 Dec 2003, 00:08:06 »
What is the error message that apears ???

Maybe the car cannot contain all of the units that you are trying to put into it ?


Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:confused
« Reply #2 on: 29 Dec 2003, 00:20:18 »
@ rhy

in dis cases it shud put as much as it can - so dat shudnt b da prob ;)

wat is realy da eror msg ?

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Pravit

  • Guest
Re:confused
« Reply #3 on: 29 Dec 2003, 00:41:47 »
There is no error message, it's just that the guys won't appear in the car.

"_x setdammage 1" foreach units _truckguys
works
_car setdammage 1
works
_captain moveindriver _car
works
"_x moveincargo _car" foreach units _truckguys
doesn't.

Here's an example mission. It won't let me attach the file, so you can get it here:
http://www.freewebs.com/pravit/WTF.zip

deaddog

  • Guest
Re:confused
« Reply #4 on: 29 Dec 2003, 15:14:35 »
It worked for me.  But the problem is this:

NEVER execute a script from the init line of a unit.

Besides, here is a better way to do what you want (this can go in the init line).

this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this])


Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:confused
« Reply #5 on: 29 Dec 2003, 16:02:12 »
Quote
NEVER execute a script from the init line of a unit.

why???

I don't see any problems with running a script from the
init line of a unit.

btw, just for info:

_truckguys = group _captain

could be exchanged with:

_truckguys = units _captain,

that way you could say:

"_x moveincargo _car" forEach _truckguys


Sometimes i do notice problems in scripts, when trying to
access units around two corners.

let's say:

_man = _this select 0

_units = units _man

"_x dosomething" forEach _units

this works fine, but:

"_x dosomething" forEach units _this select 0

doesn't work (not sure if it was especially that case, but at least
similar to that).

The problem is that the script cannot create a reference point
to unit _this select 0, as _this select 0 represents an element
of an array.

Try to put all objects/units, you need in a script, into it's/their
very own variables.

Also when debugging your scripts, try to display all contents of
your variables, to see wether they got defined properly;

hint format ["%1", _captain]

or:

hint format ["%1\n%2\n%3", _captain,_truckguys, units _truckguys]

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

deaddog

  • Guest
Re:confused
« Reply #6 on: 29 Dec 2003, 16:57:25 »
Quote
why???

I don't see any problems with running a script from the
init line of a unit.

Because not all units get initialized at exactly the same time.  When the script runs, it may be trying to perform an action on a unit that hasn't been properly initialized yet.  This will probably show up more a slower systems.  

Quote
"_x dosomething" forEach units _this select 0

doesn't work (not sure if it was especially that case, but at least
similar to that).

That's probably a good candidate for extra parenthesis :)
« Last Edit: 29 Dec 2003, 17:00:16 by deaddog »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:confused
« Reply #7 on: 29 Dec 2003, 17:13:14 »
Quote
Because not all units get initialized at exactly the same time.  When the script runs, it may be trying to perform an action on a unit that hasn't been properly initialized yet.  This will probably show up more a slower systems.

That's still no reason, not to run a script out of an init field.

I agree, that you need to know what you have to do when,
but i do not agree that running a script from an init field
should never been done.

Quote
That's probably a good candidate for extra parenthesis

nope - the extra parenthesis are in most cases just eye candy
or they're being used for better overview structure.

generally there's no difference between:

"_x blabla" forEach (units this)

and

"_x blabla" forEach units this

and

"_x blabla" forEach ((units) (this))


The problem is that the script cannot create a referback
to a suprior level of an array's elements, without isolating
the element into an individual very own string/variable/referback.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Pravit

  • Guest
Re:confused
« Reply #8 on: 29 Dec 2003, 20:48:41 »
Hmm, I see what you guys mean. Originally I was putting the code to make them go in the truck right in their init fields, but since all of these particular guys used the same script, I figured "why not put them in the truck from the script? It'll save me some copying and pasting..."

Interestingly enough, if I make "car" global, it works fine:

_captain  = _this select 0
_guys = _group captain
car = _this select 1
"_x moveincargo car" foreach units _guys

that works fine. But I have multiple squads using this script, and I'm afraid if I do something with "car" it will make it happen in each "car".
So if I want to avoid running scripts out of an init field, I just have to name each and every squad and run them all at one go in an init.sqs?

deaddog

  • Guest
Re:confused
« Reply #9 on: 29 Dec 2003, 20:59:23 »
Read this part again:

Code: [Select]
Besides, here is a better way to do what you want (this can go in the init line).

this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this])

You can put that in the init line without having to name any groups.

But, then again, what the hell do I know?

Pravit

  • Guest
Re:confused
« Reply #10 on: 29 Dec 2003, 22:49:12 »
Yes, thank you, I understand. My point was that I was already doing this in the init field of every squad:
this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this]); [this, truck] exec "somethingelse.sqs"
with "somethingelse.sqs" being a script totally unrelated to putting them into the truck.

But then I figured "Why not put the line
this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this])
into the beginning of my somethingelse.sqs script?" Then I could just write this in each one of ther init fields: [this, truck] exec "somethingelse.sqs"

Apparently it doesn't work like that, so I understand now - thanks for clearning it up.

As for naming each group, there is other stuff I want to do with them too in "somethingelse.sqs", and I don't want their init lines to get too long. So instead of having
this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this]); [this, truck] exec "somethingelse.sqs"
, should I just name the guy "fonzie" and have only this
this moveInDriver truck;{_x moveInCargo truck} foreach ((units group this)-[this])
and in a seperate init.sqs,
[fonzie, truck] exec "somethingelse.sqs"
[fonzie2, truck2] exec "somethingelse.sqs"
in order to avoid running a script from the init?