Jump to content
John Douglas

Scrip works with execVM, but NO Spawn !!

Recommended Posts

Why is it I can successfully execute the following script in the Editor Initialization, using: 
 

Executed form the Editor Initialization

using execVM (success!):

_myProcedureHandle = [this] execVM "PlayerPosition.sqf"; 

 

 

Executed form the Editor Initialization using spawn and init compile(No success!!):

 

init.sqf:

PlayerPosition = compile preprocessfile "PlayerPosition.sqf";

Editor Initialization:

_myProcedureHandle = [this] spawn PlayerPosition;  

 

And so Nothing executes using the spawn command having per-compiled with init.sqf:

 

Script: "PlayerPosition.sqf"

// File: "PlayerPosition.sqf"
// Executes with - _myProcedureHandle = [this] execVM "PlayerPosition.sqf";  
//              _myProcedureHandle = [this] spawn PlayerPosition;    

_player = _this select 0;
while {alive _player} do {
hint format ["Player Position: %1", getpos(_player)];
sleep 1;
};

I've downloaded, completed and studied examples from both Mr-Murray and Taurusv32 excellent guides, and still can't spawn the "PlayerPosition.sqf" script, where as execVM works every time ??

Share this post


Link to post
Share on other sites
17 minutes ago, John Douglas said:

_myProcedureHandle = [this] spawn PlayerPosition;

 

Where are you executing this?

Share this post


Link to post
Share on other sites
12 hours ago, gc8 said:

 

Where are you executing this?

 

Hi gc8,

 

I am executing both "execVM" and "spawn" commands from the Unit editor Initialization box. 
Using "execVM" works successfully, but I have No success with "spawn" command.
I am also scripting with "Arma Edit".

I am under the impression that my "PlayerPosition.sqf" script should work successfully under both methods of execution, and I am compiling  my spawn scripts with the use of the init.sqf
I understand the use of both local and global variables, but lack experience and most probably overlooking something fundamental. I have also stripped back all my add-ons to just Arma2 OA to simplify and maybe avoid conflicts.

 

Thanks.

 

Share this post


Link to post
Share on other sites
8 hours ago, John Douglas said:

I am executing both "execVM" and "spawn" commands from the Unit editor Initialization box. 

 

The reason it doesn't work when using spawn is because the PlayerPosition variable has not yet been created when the spawn is called.

To fix you just have to use execVM or create the PlayerPosition variable in preinit scripts

 

More info: https://community.bistudio.com/wiki/Initialization_Order

Share this post


Link to post
Share on other sites

Thanks gx8,

 

I did brief past the flow / sequence charts , but obviously didn't apply. So, I can see my character's position stored in the mission.sqm file. So with what variable do I bring forth to make sure this is initialized?

Share this post


Link to post
Share on other sites

Well you could call it like this without having to define the function in preinit:

 

this spawn 
{ 
waituntil { !(isnil "PlayerPosition") }; 

[_this] spawn PlayerPosition; 
};

 

Put that where you normally have the spawn (Init field), should do the trick

 

But using execVM would be shorter

Share this post


Link to post
Share on other sites

Thanks for elaborating with coded example, and I get your point that execVM is shorter.

Currently receive error "Type Script, expected Nothing" So added to the first line . . .  Null = this spawn . . . .and shouldn't the 3rd line also read "PlayerPosition.sqf" in quotations??

 

null = this spawn 
{ 
waituntil { !(isnil "PlayerPosition.sqf") }; 

[_this] spawn PlayerPosition; 
};

I think I can follow the logic of the code when it's published in front of me , but coming up with that ! Yikes !

Apart from trouble shooting with the use of the flowchart and working out what;s initiaised, and what hasn't been. There's No obvious errors to read from, and No clues ?? Where to start ??? I keep reviewing Murrays guide to check if I have missed anything obvious, but I might have to start reverse engineering some mission code too.

Thanks in advance again.

Share this post


Link to post
Share on other sites
1 hour ago, John Douglas said:

Currently receive error

 

Is the code you just posted giving the error? No there should be no ".sqf" becausing we are checking the existence of the variable and not the file.

 

But you should really listen haleks, that's really the best way to do this

 

Share this post


Link to post
Share on other sites

I get this Error when I paste your original code from the 6th post into the initialization box. But I'm more than willing to attempt as a function call if this is going to be more efficient.
Thanks.

 

 

Share this post


Link to post
Share on other sites
9 hours ago, John Douglas said:

I get this Error when I paste your original code from the 6th post into the initialization box.

 

It works on my machine.

 

I have this, in init.sqf:

 

PlayerPosition = compile preprocessfile "PlayerPosition.sqf";

 

Then this in the player init field:

 

this spawn  
{  
waituntil { !(isnil "PlayerPosition") };  
 
[_this] spawn PlayerPosition;  
};

 

Share this post


Link to post
Share on other sites

YES !!!! We have a Eureka moment !!!!!
Persistence pays off . . . .LOL

 

Unless I modify the initialization box to:  null=this spawn . . . . I keep getting the error "Type Script, expected Nothing"

 

I also deleted my original  init.sqf file and retyped in case it was corrupted ! Maybe !

null=this spawn    {    waituntil { !(isnil "PlayerPosition") };       [_this] spawn PlayerPosition;    };

 

So how do I turn this into my own function ????

Share this post


Link to post
Share on other sites
8 minutes ago, John Douglas said:

Unless I modify the initialization box to:  null=this spawn . . . . I keep getting the error "Type Script, expected Nothing"

 

Hmm must be arma 2 thing, I'm running arma 3.

 

Glad to hear you got it working.

 

10 minutes ago, John Douglas said:

So how do I turn this into my own function ????

 

Not sure what you mean, have you checked the links haleks gave you?

Share this post


Link to post
Share on other sites
1 hour ago, gc8 said:

Hmm must be arma 2 thing, I'm running arma 3.

Nope that's the same in Arma 3. Script boxes in editor need to end with nothing. CBA automatically fixes that though.

Share this post


Link to post
Share on other sites
1 minute ago, Dedmen said:

CBA automatically fixes that though.

 

Must be the reason I never had this problem then

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

×