Jump to content
Sign in to follow this  
Sneakers O'Toole

scripting in baby steps

Recommended Posts

I just made my first script. Not quite a masterpiece. But I stitched it together from my very limited understanding rather than just copied it.

_playerpos = getpos player;
hint format["You are at co-ord %1",_playerpos]

(crowd noise):bounce3:

Anyway. How would I make it so that it is continuously updating in real-time? I'm guessing some kind of loop?

Share this post


Link to post
Share on other sites

while loop.

Go figure out how it's done, f you have questions, ask away. Try to figure it out yourself first though.

Share this post


Link to post
Share on other sites

*noise* :hyper:

Thread title immedeately captured my eye, totally on the same boat with you, since what .. +10 years :D

As for loop, my ghetto senses tell me while do could work, no clue though about performance impacts or general economy of this approach.

while {alive player} do
{
_playerpos = getpos player;
hint format["You are at co-ord %1",_playerpos]
};

Share this post


Link to post
Share on other sites

Hi Sneakers!

You need to use the while command. Here's the code:

while {true} do
{

_playerpos = getpos player;
hint format["You are at co-ord %1",_playerpos];
sleep 0.5;

};

Share this post


Link to post
Share on other sites

Learning process ruined :(

Just a note about while do. If you are not giving it a condition to terminate after some time it will continue on and on and if you have other parts of scripts under the while loop this will not get executed.

Share this post


Link to post
Share on other sites

Heh, I've gone away from the keyboard for a moment and two posts have been written.

Share this post


Link to post
Share on other sites

sweet. Thanks for help.

I notice though that there is no ; for line 1 or 2, and that there is a ; for even just the } on line 8. Small things like this are scary.

Also, now I am thinking to have a enable/disable this function via mouse wheel menu...

But maybe I shouldn't try to run yet.

Thanks again.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

But maybe I shouldn't try to run yet.

You forgot the semi colon on the last line. :)

Share this post


Link to post
Share on other sites
sweet. Thanks for help.

I notice though that there is no ; for line 1 or 2, and that there is a ; for even just the } on line 8. Small things like this are scary.

Also, now I am thinking to have a enable/disable this function via mouse wheel menu...

But maybe I shouldn't try to run yet.

Thanks again.

You don't need to use ; on the last statement of any given scope.

example:

while {true} do { 

_playerpos = getpos player; 
hint format["You are at co-ord %1",_playerpos]; 
sleep 0.5 [color=#ff0000]// doesn't need a semi-colon because it's the last statement inside this scope[/color]

}; [color=#ff0000]// doesn't need a semi-colon either, unless you code below it. So I'll code below it.[/color]

hint "I'm writing code below the while loop, so a semei-colon is required above." [color=#ff0000]//doesn't need a semi-colon because this hint message is the end of the main scope (the script).[/color]

Edited by Iceman77

Share this post


Link to post
Share on other sites
You don't need to use ; on the last statement of any given scope.

DID NOT KNOW THIS - lol cheers Iceman

Share this post


Link to post
Share on other sites

haha you're welcome. That's one thing I've gotten my head around. I see very good scripters putting semicolons after every single statement and scope no matter what and it baffles me. But maybe it's just a good practice? idk. In any case, it's not required.

Share this post


Link to post
Share on other sites

Is there a LIST of commands anywhere..?

A huge problem for me is not knowing exactly what words are recognised. Eg, I could put "eat rations" and it wouldn't work... do you get me..?

How to know what words are available please..? This would cut down the learning time without skipping a step so to speak..?

Share this post


Link to post
Share on other sites
haha you're welcome. That's one thing I've gotten my head around. I see very good scripters putting semicolons after every single statement and scope no matter what and it baffles me. But maybe it's just a good practice? idk. In any case, it's not required.

It's pretty good practice to end every statement with ;, same for scopes. This prevents errors when you edit the script a few hours / days / months later and forgot to put a semicolon there. What I also like to do is end a scope before I add content so I don't forget that.

@meanmachine1

http://community.bistudio.com/wiki/Category:Scripting_Commands

Includes OFP & Arma.

//Edit

Aaand ninja'd by Iceman haha

Share this post


Link to post
Share on other sites
This prevents errors when you edit the script a few hours / days / months later and forgot to put a semicolon there. What I also like to do is end a scope before I add content so I don't forget that.

what? lol. If i edit it a few months later why would it matter if I forgot to put one there if it's not even required?

---------- Post added at 17:41 ---------- Previous post was at 17:38 ----------

nvm I get what you're saying. though, when writing, I generally make sure the scope / tatement above has a semicolon if nessecary

Share this post


Link to post
Share on other sites
DID NOT KNOW THIS - lol cheers Iceman

I didn't know it either but it seems sensible to do it. I find it simpler to end every statement with a ; rather than having to remember which need one and which don't. The final declaration in a function and #includes are enough already.

Share this post


Link to post
Share on other sites
haha you're welcome. That's one thing I've gotten my head around. I see very good scripters putting semicolons after every single statement and scope no matter what and it baffles me. But maybe it's just a good practice? idk. In any case, it's not required.

The only time I leave out the semicolon is if the line is supposed to be the return value of the scope.

DFS_calculateNonsense =
{
  _nonsense = 9 * _this;   
  if (_this == 4) then
  {
     _nonsense = 32;
  };

  if (_nonsense > 20) then
  {
     15  // return value
  }
  else
  {
     _nonsense  // return value
  }  // return value
};

Share this post


Link to post
Share on other sites

In the init-line of a logic:

onEachFrame { hintsilent format ["[%1,%2,%3] [%4 ASL] [%5°]",round (position vehicle player select 0),round (position vehicle player select 1),round (position vehicle player select 2), round (getposASL vehicle player select 2), round getdir vehicle player]; };

;)

Edited by RogueTrooper

Share this post


Link to post
Share on other sites
The only time I leave out the semicolon is if the line is supposed to be the return value of the scope.

I see. May I ask why? I mean if it's not required for the last statement of any scope. Is it just a good practice to do?

Edited by Iceman77

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×