Jump to content
Sign in to follow this  
MortisUmbra

Executing several lines in unit init

Recommended Posts

Hey everyone

Firstly I apologise if the answer to this question is somewhere obvious, I've been looking for an answer to this for the last couple of days - yes I've used the forum search and got 500 results, I don't have forever to sift through for an answer. I've googled for ages and looked through the murphey editor manual but cannot find anything that's useful. I'm fully expecting a link to the answer within the first reply, if so then i'm sorry!

Such a simple question...how can I put 2 init lines inside a units init box?

I've got the unit's init line as:

this moveInCargo [insert,0]; 

I want the unit to start inside the vehicle. However, I also want to run the following script too:

player execVM "savegearrespawn.sqf"

Basically I want the player to start in cargo on the vehicle (which works perfectly fine!) but I also want it to execute the script "savegearrespawn.sqf" as well. I've tried putting it in afterwards, I get told the script expects nothing. Tried putting in "and" or "&&" and the like but keep getting "missing )" or ";" etc.

Is there a way that I can do this?

Thanks

Share this post


Link to post
Share on other sites

execVM expects a scripthandle:

blah = player execVM "savegearrespawn.sqf"

To execute multiple commands in the initline, separate them with ;

this moveincargo [insert, 0]; blah = player execVM "savegearrespawn.sqf";

Share this post


Link to post
Share on other sites

Thanks for the reply Myke. Would the blah be the condition on which the script is activated?

For this particular script it's meant to spawn the player with his previously selected gear. So what would the "blah" be?

Share this post


Link to post
Share on other sites

I'm not 100% on what 'type' you'd call the 'blah', but no, it is no condition. It's just a variable, really.

I always execVM using 'xhandler'. Never use

nil = player execVM "savegearrespawn.sqf"

The 'nil' is very important. Any other 'common'/'used' variables are also not advised, i.e. anything the game already uses, or that addons people are running may use, otherwise they will collide/start over-writing each other, etc.

Again, just use xhandler - it's easy, and it works.

Feel free to ask more questions/PM me.

Regards,

- HateDread.

Share this post


Link to post
Share on other sites

I think to remember to have read that nil shouldn't be used. But don't ask me where and why.

Anyway, it is called a scripthandle. Basically it gives the runnin script instance a name and with scriptdone you can check if the script is still runnin or already finished.

Share this post


Link to post
Share on other sites

Don't use nil; it is used as a BIS constant to nullify variables, just like you wouldn't use 'time' or 'player'.

Use 0 for script handles, its a hard coded constant and can't be overridden. Ie

0 = execvm "script.sqf"

Or

 0 = [] spawn {hint "hello";};

Share this post


Link to post
Share on other sites

I didn't know we don't use player, what do we use instead of player?? And what can we use when we want the players actual name to show up in text when we do a hint how do we get it to say hint "Rommel picks up map" if we don't use player?

Share this post


Link to post
Share on other sites

@Breeze: he means that you would not use player as a return handle, such as

player = execvm "script.sqf";
// BAD BAD BAD

spawn and execVM return a handle to the script, which is just an identifier which can be used later if you wish to terminate it (very very rare), or use scriptDone command:

http://community.bistudio.com/wiki/scriptDone

If you *do* need the handle, it probably won't be inside a trigger, and you will need to give it a unique name.

Share this post


Link to post
Share on other sites

Ok I have many hours to go I am just getting to spend time with game had it forever but just finished school so now I am trying to pick this up. But thanks I appreciate all the Help I can get.

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  

×