Home   Help Search Login Register  

Author Topic: Script: Trouble with a "counter".  (Read 4037 times)

0 Members and 1 Guest are viewing this topic.

Offline rhysduk

  • Former Staff
  • ****
Script: Trouble with a "counter".
« on: 01 Sep 2006, 00:27:36 »
Hey guys.

Ive decided to "remake" a mission. So, i then decided to update a script that ill be implementing into the mission.

What I want to do is for the script to be able to determine the value of a 'variable' and act appropiately.

Ive tried the following:

Code: [Select]
Hint "Unit Postition Marking: Initializing.."
~2

#Loop

_a = _a + 1

_unit = West_1; _mark = "mark1"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]


_unit = East_1; _mark = "mark2"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]

If (_a > 1) Then  Goto "Loop"
Hint "UPM Initialized!"
Goto "Loop"

From the script above, when it intializes,  a hint is shown, waits two seconds and kicks into action.
Now the
Code: [Select]
_a = _a + 1 is the counter part of the script. So when the script gets to this bit:
Code: [Select]
If (_a > 1) Then  Goto "Loop" I want the script to skip the next line and go straight to the bottom line of the script.
I want this to happen because I only want the script to show the "HINT: UPM Initialized" once to the player, and then just cycle Lines 5 - 10 in the script.

The script isnt giving me any errors, its just doesnt do what I want it to.
Can someone spot the mistake / direct me towards the light? ( And by light i mean direction). Im not sure if this is the correct method for adding a "counter" in Flashpoint, but i have a lot of VB6 experience so thought it would be a good start.

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #1 on: 01 Sep 2006, 01:31:47 »
hmm - i remember that not initializing _a (the counter) but starting straight with increasing it
did also never work for me (*cough* hint)  :)

_a = 0

_a = _a + 1 (should now work)

:edit - just changed 'reckon' into 'remember' since 'reckon' was totally wrong word in that case  :D

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #2 on: 01 Sep 2006, 01:59:35 »
Hi,

Thanks for the reply but unfortunately it didnt make a difference.

I just dont get that last Hint! The script works by showing the units position with the markers but doesnt confirm it!
From the code it looks fool proof and i cant see how it doesnt work.
Once the script has run once, _a is at 1. So the Last Hint should be displayed.
When the script goes around again, _a is at 2, so :
Code: [Select]
If (_a > 1) Then  Goto "Loop" should goto the top of the script (Loop) and skip the last Hint for the time the script continues to run.

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #3 on: 01 Sep 2006, 02:04:48 »
Ah i see:

try this:

Code: [Select]
{If (_a > 1) Then  Goto "Loop"}
The if then (else) statement should be in quotation marks (or in *titt's* brackets {} :D  )  me thinks.

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #4 on: 01 Sep 2006, 02:10:38 »
Hey CD,

Thanks for the reply again.

This time the script continues to constantly give me the last Hint every 0.1 seconds. :(

Rhys

EDIT: Added new version of script.

Code: [Select]
Hint "Unit Postition Marking: Initializing.."
~2

#Loop

_a = 0
_a = _a + 1

_unit = West_1; _mark = "mark1"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]


_unit = East_1; _mark = "mark2"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]

{If (_a > 1) Then Goto "Loop"}
Hint "UPM Initialized!"
Goto "Loop"
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #5 on: 01 Sep 2006, 02:38:33 »
Well, this time i've read everything in your post and didn't go straight onto the problem.  ;)

First what you need me thinks is some delay: ~x
for the time you want to update your markers.

Second we will reduce the lines of your script to be processed, and also i don't think that you
need an endless increasing counter if it's just to indicate wether it's the first time or not.

Code: [Select]
_unit_array = [[West_1,"mark1"],[East1],"mark2"]]

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

"if (alive _x select 0) then {_x select 1 setmarkerpos getpos _x select 0} forEach _unit_array
"if (!alive _x select 0) then {_x select 1 setmarkerpos [0,0]} forEach _unit_array

{If (_a == 1) Then  Goto "Loop"}

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

:note - i built this up now by refering to an old mission of mine which i had stored on harddisk here at work,
i can't test it and i'm not entirely sure if i did right with the array's and subarray's check but i think it should
work like it is. If not just tell me and i'll give it another go (also my third beer is running down atm so forgive
me minor mistakes with arrays if there're any)  :shhh:  :D

:also i'm not really happy with the fact that we're still checking every round for a unit which is maybe already
dead and doesn't need anymore to be checked but this can be made later (when i'm back home and can make
myself sure in ofp).

ya know i'm comming back more and more into editing even without starting the game lately - but when it's
getting more difficult like removing subarrays from arrays i'd like to check it for myself ingame before maybe
posting some crap.  :)

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #6 on: 01 Sep 2006, 03:44:43 »
Wow thanks CD,

Right first of all, lay off that beer  :yes: lol.

Code: [Select]
_unit_array = [[West_1,"mark1"],[East1,"mark2"]]
should this be:

Code: [Select]
[[West_1,"mark1"],[East1,"mark2"]] ????

and for the IF statements, you had " opening but no closing, closing " didnt work so i removed these altogether.

Now i get this error:

Code: [Select]
if (!alive _x select 0) then|#| {_x select 1 setmarkerpos [0,0]} forEach _unit_array': Error select: Type Bool, Expected Array
hmm....

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #7 on: 01 Sep 2006, 03:55:28 »
lol - yeah you're right i had opening but forgot the closings and i mixed up East_1 with East1.
Anyways you need the if statements in quotations or ya know: titt's brackets.

here again the right code:

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1],"mark2"]]

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

"if (alive _x select 0) then {_x select 1 setmarkerpos getpos _x select 0}" forEach _unit_array
"if (!alive _x select 0) then {_x select 1 setmarkerpos [0,0]}" forEach _unit_array

{If (_a == 1) Then  Goto "Loop"}

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

Try again and if it's not working now, i need to get out off power-safing mode to let my brain work
with engines on again - but no prob at all mate - i enjoy in reinventing the rusty wheels.  :)

:edit - and here's another way reducing the script by one more line:

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1],"mark2"]]

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

"if (alive _x select 0) then {_x select 1 setmarkerpos getpos _x select 0} else {_x select 1 setmarkerpos [0,0]}" forEach _unit_array

{If (_a == 1) Then  Goto "Loop"}

Hint "UPM Initialized!"

_a = 1

Goto "Loop"
~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #8 on: 01 Sep 2006, 04:19:34 »
In the first bit of code do you mean:

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1,"mark2"]]
instead of

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1],"mark2"]] ???

and i get this error now:

Code: [Select]
if (!alive _x select|#| o) then {_x.......... : Error alive: Type Array, expected Object
Also, this script seems to continually give me the last hint, when i dont want it too.. so this means ther might be something wrong with
Code: [Select]
{If (_a == 1) Then  Goto "Loop"}
I tried taking the titt's brackets out but then i didnt get teh last hint once!

2nd Script:

the line
Code: [Select]
"if (alive _x select 0) then {_x select 1 setmarkerpos getpos _x select 0} else {_x select 1 setmarkerpos [0,0]}" forEach _unit_array is wrong.

Excuse me if u think im rude, but i dnt know whats wrong with it but CHOFPSE isnt showing that line nicely coloured (its all black) so its wrong somewhere.

Thanks for all the help Chris.
Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #9 on: 01 Sep 2006, 04:58:58 »
Nah - in no way you're appearing rude to me mate.  :)

OK, now when you say this i see i made another mistake;

the array should look like this:

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1,"mark2"]]
But the code below should be correct, even if CHOFPSE doesn't show it coloured - i'm not entirely sure if CHOFPSE
supports use of subarrays. Maybe it's just a question of the brackets so i will add some:

Code: [Select]
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0]}" forEach _unit_array
Look: _x forEach _unit_array will be: [West_1,"mark1"] - if you select 0 it should return: West_1, if you select 1 it
should return: "mark1" and same for [East_1,"mark2"]. I did not create the array correctly like you could see above,
so i think it didn't work because of this.


The line: {If (_a == 1) Then  Goto "Loop"}

you should change in a simplier line:

Code: [Select]
?(_a == 1): goto "Loop"
:remark - you don't need an if statement at this place (been blended before)

OK, here again the reworked script:

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1,"mark2"]]

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0]}" forEach _unit_array

?(_a == 1): goto "Loop"

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

OK, give it another try - if it's not working this time, i will be at home for 1 and a half hour and i promise you
i will not go to sleep before i get it working right.  :yes:

~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

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #10 on: 01 Sep 2006, 07:08:35 »
Well what can i say?

I'm back home from work and i've tried the latest version out and ... it work.  :)

Now the last bit i'm not happy with (like i already said before) is that if a unit
is not alive anymore, the script will still check every 2 seconds wether it's alive or not.
And every 2 seconds it will setmarkerpos it's marker to [0,0].

I need to get some sleep now but as soon as i get up i'll post you a solution for that.
:note - in theory it works that way: you need to build another array into which you
put every living unit and its marker, and then you say: _unit_array = another_array.
Why? - because you cannot subtract subarrays from an array, so you need this
workaround.

Otherwise you would use unnecessary performance In case you have more than two units
using this.

This will be 2 or 3 more lines in your script and that's it.

~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

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: Script: Trouble with a "counter".
« Reply #11 on: 01 Sep 2006, 10:08:36 »
Well I couldn't write scripts yet as you guys are going on it now further in this topic, but as reply to the first post, the following does what you want it too without being too hard to read  ::)

Code: [Select]
Hint "Unit Postition Marking: Initializing.."
~2
_a = 0

#Loop

_a = _a + 1

_unit = West_1; _mark = "mark1"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]


_unit = East_1; _mark = "mark2"
?(alive _unit): _mark setmarkerpos [getpos _unit select 0, getpos _unit select 1]
?(!alive _unit): _mark setmarkerpos [0,0]
?(_a > 1):goto "Loop"
Hint "UPM Initialized!"
Goto "Loop"

Greetz

as for not checking dead units a simple label (x2) with the same code but for only 1 unit would just do fine too? :)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #12 on: 01 Sep 2006, 14:40:10 »
 ??? Deja Vu  ???

lol - for some reason i get the feeling that your script has taken us straight
back to 'Start'  :D

This is definitely the same script which rhysduk postet first with the only difference
of ?(a > 1): goto "loop".

Well, in theory and even in praxis the script does it's job seven, but there's one rule
about scripting which should be considered whenever it's possible:

don't waste cpu power

Wherever you can try to avoid using multiple lines if you can do it in one single line.
Imagine what if a script like this runs for 50 units: The checkdead setmarkerpos stuff will increase
to 150 lines.  :blink:

And the counter _a you also increase it by 1 every 2 seconds. After 30 minutes the counter arrives 900  :o
and still counting upwards (like the elevator comming out of the roof).

Quote
as for not checking dead units a simple label (x2) with the same code but for only 1 unit would just do fine too?

Yeah, 2 more lines two prevent going through two other lines  :)
_unit = ya know
?not alive: goto "skipit"
....
....
"skipit"

Wow, now 20 units would end up with 100 lines for the check-stuff only.

Don't get me wrong Seven, but that's been the reason why i broke my
brain yesterday in the night. The only prob was that i ain't got ofp at work
and i can't test stuff there, so it took a while to make this script error-free.

btw rhysduk, i'll go for the remove deads from array after moving marker to 0,0
stuff now.  :yes:

~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

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: Script: Trouble with a "counter".
« Reply #13 on: 01 Sep 2006, 15:09:56 »
 :D right ok well if it were for just those 2 units I wouldn't bother as it was posted :p
You got my attention Chris  :)


ps: as from the beginning I saw in the  3rd post that the first solution didn't go down till Hint "UPM Initialized!"
that's why I dared posting  :afro:

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #14 on: 01 Sep 2006, 15:21:47 »
@CD

Thanks m8  :thumbsup: I tried your script and hey presto it works! Thanks a lot Chris!

I get no error now with this line:

Code: [Select]
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0]}" forEach _unit_array
Ill have a crack at that dead unit array and keep you posted.  :cool2:

@Seven

Thanks for the post seven, the updated script of my first post that you posted, does work! But like CD said, it is rather heavy on CPU Power! ;)

Thanks guys!

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #15 on: 01 Sep 2006, 15:43:04 »
Hey Rhysduk, i just finished the last part like i said:

I'll post you two versions - one for your setup and another one a little bit
improved (lol - CD the Improvator).

Code: [Select]
_unit_array = [[West_1,"mark1"],[East_1,"mark2"]]
_temp_array = []

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

#back
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0][b]; hint format [{%1 will be removed now},(_x select 1)][/b]; goto {remove}}" forEach _unit_array

?(_a == 1): goto "Loop"

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

#remove

"if (alive (_x select 0)) then {_temp_array = _temp_array + [_x]}" forEach _unit_array

_unit_array = _temp_array
_temp_array = []
goto "back"

:note - the phat line inside was just a hint for me you can remove it if you want

Well, that's the version based on your method of assigning the unit within the script.

Now i've made another version, where you can add as many units as you want without having
to edit the script.

If you have an init.sqs, put inside: unit_array = []
If not, make it from inside the first unit you've placed onto the map.
If the first unit being placed onto the map should run the markerupdate script, then put
the following code in it's init field instead:
unit_array = [[this,"markx"]]

:note it's important to initialize an array before adding elements to it therefore this method.
::note - markx you should replace with the marker name of the unit

Now into each unit's init field, which should run the script too put:

unit_array = unit_array + [[this,"markx"]]

The script you start best from a trigger, because triggers will for sure become active after the last
unit's init field has been executed (just take a look into mission.sqm and you'll see sensors come
after the units).

trigger: size 0/0
condition: true
onActivation: [] exec "markerupd.sqs"

:note - or whatever you call your script

And here's the modified script for that method:

Code: [Select]
_temp_array = []

_a = 0

Hint "Unit Postition Marking: Initializing.."

#Loop

~2

#back
"if (alive (_x select 0)) then {(_x select 1) setmarkerpos getpos (_x select 0)} else {(_x select 1) setmarkerpos [0,0][b]; hint format [{%1 will be removed now},(_x select 1)][/b]; goto {remove}}" forEach unit_array

?(_a == 1): goto "Loop"

Hint "UPM Initialized!"

_a = 1

Goto "Loop"

#remove

"if (alive (_x select 0)) then {_temp_array = _temp_array + [_x]}" forEach unit_array

unit_array = _temp_array
_temp_array = []
goto "back"

:note - basically it's the same script with the only difference of using a global array: unit_array
and not having assigned the array inside the script.

You can also make a radio trigger now to hint format ["%1",unit_array] so that you can
see the content of the array.

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #16 on: 01 Sep 2006, 16:08:00 »
Hey Chris.

Thanks!

I tried the detecting a dead unit but failed miserably.

Right here what ive done so far:
  • In the init.sqs added unit_array = []
  • In the Init field of each unit, i put unit_array = [[this,"markx"]] (Replace markx for relevant name of marker.)
  • Also added unit_array = unit_array + [[this,"markx"]] to each units Init field.
  • Added a West, Present, 0,0, Cond: true, On Activ: [] exec "unit_mark.sqs"
  • Added your final script to the mission folder and saved.
  • Saved everything, load Flashpoint. Run mission.
  • No error! But the markes just sit where they were put in the mission editor and dont attach to each unit!

Ill take another read of your post just in case ive done something wrong!

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

Pride and Joy 1 (HW100-T)

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #17 on: 01 Sep 2006, 16:15:07 »
Right, I also tried the following.

According to the mission.sqm file, the PLAYER is the first person initiated on the map.

  • So in his Init field i put unit_array = [[this,"mark3"]] (mark3 is the marker to show pos of player.)
  • In the other two units Init fields i put unit_array = unit_array + [[this,"markx"]] and changed markx accordingly.

This didnt work either. Again no error! All 3 markers stay at the mission editor postion :(

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #18 on: 01 Sep 2006, 17:41:01 »
hmm - i tried again now making it exactly how you did;

I've placed the player onto the map and in his init field i've put:

unit_array = [[this,"mark3"]]


Then i added two more units and in the init fields i've put:

unit_array = unit_array + [[this,"markx"]] markx accordingly.

I placed the three markers

And i placed a trigger: 0/0

Activation: West / present
Condition: true
onActivation: [] exec "unit_mark.sqs"

Started the mission and voilla it worked.
Well, the only problem i got was that after killing a unit an error popped up because of: hint format......
But that was because it seems that when using code here on the forums, the ... will not display it phat
but just the code itself. So remove the and the .

But this shouldn't be your problem since the markers were moving from start and this error shows up first time
when you kill a unit.

I suppose you have mixed something up in order of creating the array and adding the units or you have a simple
typo somewhere.
Maybe some names do not match - most i suspect it on the array name or the script name.  ;)

Anyways, i'll attach a working example to the post so that you can see yourself.

It's on desert island just for ya info.

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #19 on: 01 Sep 2006, 18:06:20 »
Thanks for that CD.

I tried your example missionand it does indeed work!

But i couldnt see the line unit_array = [] anywhere?
Which is what you said to put in the init.sqs file.

So i took this out of my init file and tried again.

This time only the player and 1 unit had their markers work. the other guy (enemy - East) marker didnt work it just sat there.. :(

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #20 on: 01 Sep 2006, 19:06:45 »
Well, you can initialize an array by: unit_array = []

Or by directly filling it with something like i did in player's init field (the very first unit on the map):

unit_array = [[this,"mark3"]]

If you somewhere after this say: unit_array = [] you will clear it off course again.

But upon the fact that only the player and one unit had a working marker, while their east unit's
markers were just sitting in place i suspect that it probably was like this:

init.sqs: unit_array = []

east units init fields: unit_array = unit_array + [[this,"markx"]]

followed by the player: unit_array = [[this,"mark3"]]

followed by the one unit where it's been working: unit_array = unit_array + [[this,"markx"]]

 :)

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #21 on: 01 Sep 2006, 19:20:15 »
Ive figured out why its not working.. Its because the Unit is EAST and not WEST like the other two units (whose markers are working)

How do i solve this? Perhaps check the SIDE of the unit through the script, if its possible?!

Rhys

EDIt: Ive looked at the COMREF and not sure how i can use side .....
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #22 on: 01 Sep 2006, 20:14:34 »
Well Rhysduk, it's weird but true  :o

But don't worry i got the solution for ya aswell:  :)

I figured out that east unit's init fields become executed before west unit's init fields.

This means that all you need to do is;

change the west player's init field into: unit_array = unit_array + [[this,"mark3"]]

and change the very first east unit's init field into: unit_array = [[this,"markx"]]

Strange but i did never take notice of that - maybe it's because E is comming before W
in alphabetical order.  ???

:btw - i attached another working example, this time featuring the player, two west and two east units.

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #23 on: 01 Sep 2006, 21:09:24 »
Call me Rhys m8  :)

Quote
I figured out that east unit's init fields become executed before west unit's init fields.

 :o How? I took a look at the mission.sqm file and WEST units appear to be executed/initiated before EAST units.. im curious how you did that. Another of you array/sub arrays...

Everything works now.. thanks!

Topic left open for few hours for replys, will be locked later.

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

Pride and Joy 1 (HW100-T)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Script: Trouble with a "counter".
« Reply #24 on: 01 Sep 2006, 21:24:09 »
lol - i figured that out by trying / wondering and trying more:  :D

First i made it like we had it before and i saw that east units weren't included to
the array.

This made me think that west and east units can't be together in an array.

But i remember from my MOTAG (MOre Than A Group) that i head already east and west
units together in an array -> so this couldn't have been the reason.

Then i thought that maybe you cannot add them together into arrays - i tried to manually
setup the array: unit_array = [[w1,"mark1"],[w2,"mark2"],[e1,"mark4"],[e2,"mark5"]]
and all units were included to the array when i displayed it ingame.

Then i thought to tell you that but suddenly a flash came into my brain: who's init field gets
really executed first?

So i tried the following:

I've put:
a = 1
in player's inti field (the first unit i placed onto the map)

and by adding an east unit with an init field like: a = 2

Then showing the value of a on screen resulted in: 1

Then i made: a = 1 with the east unit
and a = a + 2
with the player.
Result showing up on screen was: 3

This lead me to the conclusion that east units get executed before west units no matter
whom of them has been placed first.

Like i said, maybe it's because East comes before West in alphabetical order.

However - we got it finally working and i could also learn something new.  :)

Isn't OFP just wonderful?  :thumbsup:

~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

Offline rhysduk

  • Former Staff
  • ****
Re: Script: Trouble with a "counter".
« Reply #25 on: 01 Sep 2006, 21:36:04 »
Ah right I see. Clever i must say.

Quote
Isn't OFP just wonderful? 

Oh yes, indeed it is.

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

Pride and Joy 1 (HW100-T)