edc 0 Posted July 10, 2003 In a cutscene, I'm trying to make the camera follow an apache, until it gets fairly close to a gamelogic called place. I looked at the command reference to what OFP's syntax for loops was, and made a while loop as follows: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while "(apache1 distance place)>250" do {_cam camsetrelpos [15,25,-10];_cam camcommit 0;~0.1} OFP gives me this: It does show the quotes around the condition in the command reference, so I assume it should be that way. Share this post Link to post Share on other sites
toadlife 3 Posted July 10, 2003 You can't have this--> ~0.1.... ...In a while>do statement. Remove it and see what happens. Share this post Link to post Share on other sites
edc 0 Posted July 11, 2003 It still gives me that error. Share this post Link to post Share on other sites
toadlife 3 Posted July 11, 2003 ok try putting "_cam camsetarget apache" in the loop. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> while "(apache1 distance place)>250" do {_cam camsettarget apache1; _cam camsetrelpos [15,25,-10];_cam camcommit 0;} Share this post Link to post Share on other sites
ralphwiggum 6 Posted July 11, 2003 something is wrong with edc's while loop statement. (i'm assuming that the camera was correctly initialized and is targetting apache1.) if this causes problem, try the good old fashion way. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> #apacheloop ?((apache1 distance place)<250) goto "endapacheloop" _cam camsetrelpos [15,25,-10] _cam camcommit 0 ~0.1 goto "apacheloop" #endapacheloop Share this post Link to post Share on other sites
edc 0 Posted July 11, 2003 Thanks, the old way works. Share this post Link to post Share on other sites
bn880 5 Posted July 11, 2003 Yeah! You were missing a semicolon at the end of the while statement. while "<condition>" do {<statement>}; (oh no, this reminds me of compilers) Share this post Link to post Share on other sites
toadlife 3 Posted July 11, 2003 @bn880: You don't need a semicolon at the end as long as it's not a function. @edc: My bet is you had a typo somewhere above that line you posted. Wanna post a little more of the original script you were trying to get working? Edit: nope looks like camera commands just dont work in while do statements Share this post Link to post Share on other sites
dinger 1 Posted July 11, 2003 jeezus guys. Quote[/b] ]while "(apache1 distance place)>250" do {_cam camsetrelpos [15,25,-10];_cam camcommit 0;~0.1} And ye call yourselves scripters! ~ is not a command that works in functions. Functions are executed immediately, with no other concern on the processer. If you dump too much to a function, OFP will shut down. So: the while {} do {} loop with ~ won't work because ~s don't work in functions, since they are by definition executed immediately. the while {} do {} loop wihtout the ~ won't work because everything else stops while a function is being run. It has nothing to do with camera or no camera, and everything to do with how functions work. TL, you had it right the first time. Never waver, and never blame OFP for not supporting something. Blame it for supporting something poorly. Share this post Link to post Share on other sites
toadlife 3 Posted July 11, 2003 Actually Dinger I set up a test mission and could not make a camera follow my chopper using a while loop. It just wouldn't work at all. That's why I said camera commands don't seem to work in while loops Share this post Link to post Share on other sites
dinger 1 Posted July 11, 2003 Well, that still doesn't prove that camera commands don't work in while loops. Try this one: while {_cam distance _target > 200} do {_Cam camsetrelpos [(_cam distance _target)/2, 0, 0]; _cam camcommit 0} My bet is that this will create a static camera shot of the target from 100<x<200. There will be no motion. The underlying rule is everything stops when a function runs. A while loop is a function. And you'll probably see a CTD if you make a while loop depend on an external condition. So, now correct me if I'm wrong here, but wouldn't this boil down to: the condition in a while loop must be met by loop's function.? If you have a condition that is determine by something external to the do loop, the condition will never verify. Share this post Link to post Share on other sites
bn880 5 Posted July 11, 2003 OK lol, but Dinger, the ~ comment was made by post two. This question seems to be a minefield for some scripters, including me. Share this post Link to post Share on other sites
toadlife 3 Posted July 12, 2003 I see now. I never realized that while statements acted as functions even when run from within normal OFP scripts. You can do these.... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {_time < 2} do {_Cam camsetrelpos [0,-15,0]; _cam camcommit 0;hint "testhint";} <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {fuel mycar > .9999} do {_Cam camsetrelpos [0,-15,0]; _cam camcommit 0;hint "testhint";} ...and they will sound 10,000 hints, and then error out, with the camera being positioned at the correct place after the functions stop. The error is a good thing or our PCs would lock up even harder than the old days when endless loops lockups. I noticed that functions can only check their condition 10,000 times and then they will error out automatically. This will work... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _x = 0 while {_x < 9999} do {_x = _x + 1} This will not... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _x = 0 while {_x < 10000} do {_x = _x + 1} Share this post Link to post Share on other sites