Home   Help Search Login Register  

Author Topic: okay, that's it, i've had enough...  (Read 745 times)

0 Members and 1 Guest are viewing this topic.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
okay, that's it, i've had enough...
« on: 18 Dec 2004, 17:48:54 »
i am up to my eyeballs in brackets and nested commands, and even though i wanted the personal satisfaction of getting this to work myself, to hell with it, i'll just ask.

scenario. i am setting up a cutscene where a group of loons will execute a prisoner and then keep shooting. my idea was to pan the camera up after the first loon dies and then start createunit-ing some more soldiers out of view for the loons to fire at. instead of using about 30 named soldiers 'off-stage' and pulling them in one at a time, i thought using an incremented array and the <call>/<format> commands would ease the workload a little.

insert ironic laugh here.

with pointers from various tutorials and posters (thankyou all) this is what i have so far:

Code: [Select]
_i = 0

#loop
_soldiername = format [%1 + %2,"bert",_i]

call {format [%1 + %2 + %3,""SoldierWB" createUnit [getmarkerPos "bertplace", targets,"_soldiername,"=this"]"]}

_i = _i  + 1
?_i=20:exit
goto loop

now the error message says i have brackets missing, but i'm thinking that's just one of many problems. all those """ together can't be right.

i read somewhere (i think) that "" and {} are interchangeable, like "" and '' are in html/javascript.

what on earth is going on here? i feel i'm just a step away from getting it to work but have no idea how.

i know it's cheating to ask. i know. i do feel suitably ashamed believe me.  :-\

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:okay, that's it, i've had enough...
« Reply #1 on: 18 Dec 2004, 18:20:44 »
When OFP says there's a missing bracket, it can be any of the brackets: ( { [

The whole format thingy is screwed in that script though...

The soldiername thingy should ne like this:
Code: [Select]
format ["bert%1",_i]
And I believe the creatunit format should be something like this...
(Altough I don't have clue what you mean with the %1+%2+%3... ???)

Code: [Select]
call {format ["{SoldierWB} createUnit [getmarkerPos {bertplace}, targets,{%1=this}]",_soldiername]}

Note that might not work, I suck with the format function :P
« Last Edit: 18 Dec 2004, 18:21:26 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:okay, that's it, i've had enough...
« Reply #2 on: 18 Dec 2004, 22:09:20 »
me too it seems. i give up. i'll do it the old-fashioned way.

for reference, the code you sent did indeed work, or say rather that it runs through without any errors. but if the unit is being created, then it's invisible. i put a hint into the code to check, and it only runs once, even with a loop put in.

like i say, i give up. i'll live with the shame.

thanks anyways :)

Offline Mud_Spike

  • Contributing Member
  • **
Re:okay, that's it, i've had enough...
« Reply #3 on: 18 Dec 2004, 22:34:43 »
First off, the format command wants a format string and then the format arguments.
I.e.; format ["Hello %1, your age is %2", _name, _age]
Not  format [%1+%2, "Hello your age is", _name, _age] .. or whatever you have going there.

Hater_Kint was telling you this for the first use of it, _solderianame, all good, but
the messy createUnit format is also passed invalid arguments.

Instead of trying to unnest it and figure out what you actually want out of it, I suggest
a simpler approach.
Code: [Select]
_phony = []
_phony resize 12
_units = []
{"soldierWB" createUnit [getMarkerPos "mrk_x", test_grp, "foo=this"] ; _units = _units + [foo]} foreach _phony

Where "mrk_x" is where you want them created and test_grp is an existing group (importante!).
'... resize 12' is the number of units that'll be created, note however that a group
can carry no more than 12 units, so if you go beyond 12 you'll have to figure out a way
to provide another group name. Simplest approach is probably just to copy the foreach
line and change the group name.

Oh yeah, the units will be available in the _units array if you ever want to remove them
or whatnot.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:okay, that's it, i've had enough...
« Reply #4 on: 18 Dec 2004, 23:13:15 »
thanks for clearing the format syntax up there. i see where i was going wrong.

the rest, populating arrays like that... whoosh. straight over my head. i haven't even touched the foreach command yet and this is the thing - i like to understand what i'm scripting. i can't see where you're getting the foo value from... or is that just a temporary variable to pass along the soldier identity? see what i mean? whoosh....  :-[

as i said, i've just done it the long way round, hiding a few target practice units out of scene and then just moving each into place on the death of the previous. works just fine, and no limit to numbers other than how many i can be bothered to copy n paste.

looking at the code though.... heheh i find this kind of problem irresistable, i can't help myself.... so if i tried to access the created units i'd use

_units select 0-11?

the knowledge is trickling through slowly but surely, but it's so long since i did any programming, my brain's out of practice.

for the moment, i'll stick to the long-winded method until i can learn some more from other tutorials and mission scripts. best way to learn i find.

thanks meantime

Offline Mud_Spike

  • Contributing Member
  • **
Re:okay, that's it, i've had enough...
« Reply #5 on: 18 Dec 2004, 23:42:29 »
I hear you buddy, do what works for you and keeps you happy.
I'll take this opp to explain what the code snippet does however, line by line.

Code: [Select]
_phony = []Tells OPF _phony is an array, we need it to know this for the next command
that resizes an array.
Code: [Select]
_phony resize 12Makes room for 12 whatevers (the element type is unknown and irrelevant at this point) in our array _phony.
Code: [Select]
_units = []Initialize a second array, _units, telling OPF it is an array. It needs to know this
when we start adding elements to it.

Code: [Select]
{"soldierWB" createUnit [getMarkerPos "mrk_x", test_grp, "foo=this"] ; _units = _units + [foo]} foreach _phonyWe'll break this one up.

Syntax: "cmdstring..." foreach array
It will run "cmdstring..." for each element of array and replace _x in the command string
with the current element in the array. However, it doesnt require _x to exist in the command string, so foreach is of great use when you want to do something a couple of times without doing a loop (since making goto-loops in sqs:es gets boring quite quickly).

As you said earlier, { } and "" are inter-exchangable.
So, what we do is tell foreach we want to execute our command string 12 times, remember, _phony has the size of 12.

The commandstring is:
Code: [Select]
{"soldierWB" createUnit [getMarkerPos "mrk_x", test_grp, "foo=this"] ; _units = _units + [foo]}
Or split up even further:
Code: [Select]
"soldierWB" createUnit [getMarkerPos "mrk_x", test_grp, "foo=this"]
_units = _units + [foo]

The arguments to createUnit (the ones we use anyway) are:
[position, group, "init-string"].  GetMarkerPos.. and test_grp are self-explanatory.
As we want to keep track of the units we create, we assign 'this', which is always the unit that is being created in the init-string, to the temporary variable 'foo', just as you guessed.

Then we add that variable, or actually the value of it, which is the handle of the unit at this point, to our _units array. Thats the second line. (_units = _units + [foo]).
There is a great tutorial on arrays by snypir in the editing section - a must read.

And yeah, to extract the different unit handles from the array you'll use '_units select 0-11', you are right again.

Okidoki, I think that sums it up.

Good luck.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:okay, that's it, i've had enough...
« Reply #6 on: 19 Dec 2004, 00:07:56 »
and thus the clouds did part, and lo, the sun shone forth...

it's so easy when you put it like that!

i've pored over snypir's tutes and could just about see what what was going on. see, all the principles of programming i remember - multidimensional arrays, nested loops and so forth, but the syntax from language to language....

that makes things a heap clearer, many thanks.