Home   Help Search Login Register  

Author Topic: Script: Trouble with a "counter".  (Read 4039 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)