OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: max_killer_payne on 12 Jul 2003, 15:24:06

Title: Ending a loop
Post by: max_killer_payne on 12 Jul 2003, 15:24:06
How can I end a loop, Sui is kindly helping me with this. But scince he cant guarantee it being ready (I need this thing now!!) I was wondering if some1 could help me, and LCD your one didnt work!!  ???
Note than man is a pilot in a plane

Code: [Select]
_cam = "camera" CamCreate [0,0,0]
_cam CameraEffect ["internal","back"]

#loop
_cam camsettarget man
_cam camsetrelpos [0,50,50]
_cam camcommit 0.03
@camcommitted _cam
_cam = _cam + 0.0020
? (_cam> 0.007) : goto "Done"
goto "loop"

#Done
_cam camsettarget man2
_cam camsetrelpos [23,0,56]
_cam camcommit 0
@camcommitted _cam


Whats wrong?
I want it to go to Done after 20 seconds
Title: Re:Ending a loop
Post by: KTottE on 12 Jul 2003, 16:26:12
http://www.ofpec.com/editors/browse.php?browsewhat=2&category=2_12

Use that instead.
It works. It also holds the solution to your problem, though I can't be bothered fetching it for you, just check the script(s) in there.
Title: Re:Ending a loop
Post by: max_killer_payne on 12 Jul 2003, 16:30:16
I cant find anything about ending a loop in there ???
Title: Re:Ending a loop
Post by: KTottE on 12 Jul 2003, 16:36:19
Wrong URL from me.
http://www.ofpec.com/editors/resource_view.php?id=152
Title: Re:Ending a loop
Post by: LCD on 12 Jul 2003, 16:38:19
Code: [Select]
_cam = "camera" CamCreate [0,0,0]
_cam CameraEffect ["internal","back"]

_I = 0
#loop
_cam camsettarget man
_cam camsetrelpos [0,50,50]
_cam camcommit 0.03
@camcommitted _cam
~0.1
_I = _I+0.1
? _I==20 : goto "Done"
goto "loop"

#Done
_cam camsettarget man2
_cam camsetrelpos [23,0,56]
_cam camcommit 0
@camcommitted _cam

tel me if dat work ;)

LCD OUT
Title: Re:Ending a loop
Post by: max_killer_payne on 12 Jul 2003, 17:26:05
Nah, dont work
Title: Re:Ending a loop
Post by: Rubble_Maker on 12 Jul 2003, 23:25:58
The counter is unreliable coz the @ forces ofp to wait for the camera; no way to predict how many msecs that costs. Also the ~0.1 is not good because ofp will not really wait for 0.1 seconds, it will run the next loop cycle when its *close to 0.1 seconds later AND it is convenient for the engine to do some script execution*. That means: If the engine is too busy doing other stuff, it will neglect the script and the 0.1 delay will get bigger in reality.

Here's a stable solution:

_cam = "camera" CamCreate [0,0,0]
_cam CameraEffect ["internal","back"]
_endTime=TIME+20

#loop
_cam camsettarget man
_cam camsetrelpos [0,50,50]
_cam camcommit 0.03
@camcommitted _cam
_cam = _cam + 0.0020
?TIME<_endTime:goto "loop"

_cam camsettarget man2
_cam camsetrelpos [23,0,56]
_cam camcommit 0
@camcommitted _cam
Title: Re:Ending a loop
Post by: max_killer_payne on 13 Jul 2003, 09:30:23
cheers Rublemaker
Title: Re:Ending a loop
Post by: max_killer_payne on 13 Jul 2003, 10:06:21
Shouldnt it be

Code: [Select]
?TIME<_endTime:goto "stopcam"
rather than

Code: [Select]
?TIME<_endTime:goto "loop"
Title: Re:Ending a loop
Post by: Rubble_Maker on 13 Jul 2003, 16:13:20
No

Think about it! TIME is the seconds passed since the start of the mission. Adding 20  to it goes 20 secs into the future. So as long as the current time is smaller than this value, the loop will go on.