Jump to content
Sign in to follow this  
HateDread

Script Not Functioning - Exec - Howto?

Recommended Posts

player sidechat "Check 1";

if (East == 1) then exec "SpawnEast.sqf";

if (West == 1) then exec "SpawnWest.sqf";

if (North == 1) then exec "SpawnNorth.sqf";

Player sidechat "Check 2";

This fires Check 1, but not Check 2. What is wrong with it?

Cheers.

Share this post


Link to post
Share on other sites

A couple of things by the look of it.

exec is used to execute .sqs files not .sqf

I am assuming you haven't got below in your mod line. I highly recommend it as otherwise the scripts can just terminate with errors leaving you none the wiser. This will produce an error message to help fix the problem.

-showScriptErrors

Try something like:

If (East1 == 1) then {_null = execVM "SpawnEast.swf";};

Also not to sure about this one, but East is a predefined variable and this might mess things up to. Without seeing the rest of the script probably better to rename .

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

Share this post


Link to post
Share on other sites

Thanks a lot! I added that startup to modline, but I don't know where it shows those errors.

Here's the script, meant to randomly select one of three spawn points. All checks fire, but the script being executed does not run.

SpawnNumGen = random 3;

If (SpawnNumGen == 1) then

{

EastS = 1;

WestS = 0;

NorthS = 0;

};

If (SpawnNumGen == 2) then

{

EastS = 0;

WestS = 1;

NorthS = 0;

};

If (SpawnNumGen == 3) then

{

EastS = 0;

WestS = 0;

NorthS = 1;

};

player sidechat "Check 1";

If (EastS == 1) then {_null = execVM "SpawnEast.sqf";};

If (WestS == 1) then {_null = execVM "SpawnWest.sqf";};

If (NorthS == 1) then {_null = execVM "SpawnNorth.sqf";};

Player sidechat "Check 2";

Sleep 30;

Any ideas?

Share this post


Link to post
Share on other sites

Problem 1 would be that

Random 3

It generates number between 0. - 3.0

Also what that script is ment to do can be done in many ways.

Looks like a perfect opportunity to introduce yourself to Switch structure.;)

_SpawnNumGen = random 2;
_SpawnNum = Round _SpawnNumGen;

player sidechat "Check 1";

Switch (_SpawnNum) do
{
 	Case 0 : {_null = execVM "SpawnEast.sqf";};
 	Case 1 : {_null = execVM "SpawnWest.sqf";};
 	Case 2 : {_null = execVM "SpawnNorth.sqf";};
};

Player sidechat "Check 2";

Share this post


Link to post
Share on other sites

Thank you! The scripts finally run!

Could you please explain what that code does? Like...

Why have a 'random 2' instead of 3, if we're doing 3 options, etc?

Cheers.

Share this post


Link to post
Share on other sites

Thank you.

I don't understand the first line of this;

Switch (_SpawnNum) do

{

Case 0 : {_null = execVM "SpawnEast.sqf";};

Case 1 : {_null = execVM "SpawnWest.sqf";};

Case 2 : {_null = execVM "SpawnNorth.sqf";};

What does 'switching' the rounded result have to do with these 'cases'? Is case 0 selected where the rounded result equals 0, and so on? If so, is this always the case? (Pardon the pun).

Share this post


Link to post
Share on other sites

switch is a command. It compares the variable in question (_SpawnNum here) to the cases.

It is an alternative to nested if-else:

_var = 2;

if (_var == 0) then
{
    hint "Var is 0";
}
else
{
    if (_var == 1) then
    {
         hint "Var is 1";
    }
    else
    {
         if (_var == 2) then
         {
              hint "Var is 2";
         }
         else
         {
              if (_var == 3) then
              {
                   hint "Var is 3";
              }
              else
              {
                   hint "Var is something other than 0, 1, 2 and 3";
              };
         };
    };
};

This is obviously rather nasty, now let's try the same exact thing with switch:

_var = 2;

switch (_var) do
{
    case 0:
    {
         hint "Var is 0";
    };
    case 1:
    {
         hint "Var is 1";
    };
    case 2:
    {
         hint "Var is 2";
    };
    case 3:
    {
         hint "Var is 3";
    };
    default:
    {
         hint "Var is something other than 0, 1, 2 and 3";
    };
};

Share this post


Link to post
Share on other sites
round (random 2) can give you 3 values: 0, 1 and 2

Yes that is better.

Way i wrote it gives west twice the change over east and north:o

Share this post


Link to post
Share on other sites

I edited this script;

_SpawnNumGen = random 2;

_SpawnNum = Round _SpawnNumGen;

_SpwnCountr = 0;

while {_SpwnCountr < 10} do

{

player sidechat "Check 1";

Switch (_SpawnNum) do

{

Case 0 : {_null = execVM "SpawnEast.sqf";};

Case 1 : {_null = execVM "SpawnWest.sqf";};

Case 2 : {_null = execVM "SpawnNorth.sqf";};

};

Player sidechat "Check 2";

_SpwnCountr = _SpwnCountr + 1;

Sleep 25;

};

Each script it's executing has an identifying 'player sidechat' command. because of this, I can see it always ends up as whatever the first result is - if the first was an 'East', they are all an 'East'.

---

Each script looks like this;

Player sidechat "Check 3";

[EastPOS,12] call CHN_UNDEAD_fn_CRTZEDGRP;

Player sidechat "Check 4-E";

With the relevant spawn position and 'check'. Check 4 always fires a long time after check 3, and I don't know why.

Any ideas, for either problem?

EDIT: I realise the first problem - I was not re-executing the randomise command in each loop, so the result stayed the same. New script is;

_SpwnCountr = 0;

while {_SpwnCountr < 10} do

{

_SpawnNumGen = random 2;

_SpawnNum = Round _SpawnNumGen;

player sidechat "Check 1";

Switch (_SpawnNum) do

{

Case 0 : {_null = execVM "SpawnEast.sqf";};

Case 1 : {_null = execVM "SpawnWest.sqf";};

Case 2 : {_null = execVM "SpawnNorth.sqf";};

};

Player sidechat "Check 2";

_SpwnCountr = _SpwnCountr + 1;

Sleep 25;

};

Still got that second question open to the public, though.

Cheers.

Edited by HateDread

Share this post


Link to post
Share on other sites
Yes that is better.

Way i wrote it gives west twice the change over east and north:o

And doing round random 2 gives following chances:

0: 25% (0-0.49)

1: 50% (0.5-1.49)

2: 25% (1.5-1.99)

If you want to have even chances you should do:

floor random 3

Share this post


Link to post
Share on other sites

How's this, then?

_SpwnCountr = 0;

while {_SpwnCountr < 10} do

{

_SpawnNum = floor random 3

player sidechat "Check 1";

Switch (_SpawnNum) do

{

Case 0 : {_null = execVM "SpawnEast.sqf";};

Case 1 : {_null = execVM "SpawnWest.sqf";};

Case 2 : {_null = execVM "SpawnNorth.sqf";};

};

Player sidechat "Check 2";

_SpwnCountr = _SpwnCountr + 1;

Sleep 25;

};

Share this post


Link to post
Share on other sites

Here is 3 different versions that all do the same. Last two call the spawning function right away instead of execing a new script. Pointless to put it into a new script file unless it's really needed. First version is same as yours.

for "_i" from 0 to 10 do {
 switch (floor(random 3)) do {
   case 0: { execVM "SpawnEast.sqf" };
   case 1: { execVM "SpawnWest.sqf" };
   case 2: { execVM "SpawnNorth.sqf" };
 };
 sleep 25;
};

for "_i" from 0 to 10 do {
 switch (floor(random 3)) do {
   case 0: { [EastPOS,12] call CHN_UNDEAD_fn_CRTZEDGRP };
   case 1: { [WestPOS,12] call CHN_UNDEAD_fn_CRTZEDGRP };
   case 2: { [NorthPOS,12] call CHN_UNDEAD_fn_CRTZEDGRP };
 };
 sleep 25;
};


for "_i" from 0 to 10 do {
 call compile format ["[%1,12] call CHN_UNDEAD_fn_CRTZEDGRP",["EastPos","WestPos","NorthPos"] select (floor(random 3))];
 sleep 25;
};

Share this post


Link to post
Share on other sites

Thanks!

I don't understand the for "_i" from 0 to 10 part. Is this like what I had; while {_SpwnCountr < 10} do? If so, I simply change the 10 to whatever maximum I want?

Cheers.

Share this post


Link to post
Share on other sites

Yes, it's a for-loop, which does exactly same as your while-loop, except it assigns the value to _i automatically. The value range you can define with the from x to y. So, yes, you can change 10 to whatever maximum you wish.

Share this post


Link to post
Share on other sites

How would I set it up so that a variable is set to true/1, signifying this spawn loop/script is over, so that I can call something else to follow it, that must wait for this loop to finish, first?

Cheers.

Share this post


Link to post
Share on other sites

Method 1: using scriptdone

whatever script the spawn script is called from

_scriptHandle = execvm "spawn.sqf";
waituntil {scriptdone _scriptHandle};

spawn.sqf

for "_i" from 0 to 10 do {
 switch case spawning stuff here
};

Method 2: variable

Trigger condition: YourGlobalVariable

Script waiting: waituntil {!isnil "YourGlobalVariable"};

Alternative way would be to check if it's true with: waituntil {YourGlobalVariable}, but in that case you would need to initialize it (to false) somewhere that is executed before the waituntil line.

spawn.sqf

for "_i" from 0 to 10 do {
 switch case spawning stuff here
};
YourGlobalVariable = true;
publicvariable "YourGlobalVariable";

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  

×