Jump to content
Sign in to follow this  
sas troop

Strange Switch syntax problem

Recommended Posts

This is my script, easy like heaven:

_liczba = floor (random 2);

switch (_liczba) do
{
   case 1:
   {
oficer setpos (getpos ldver1_pos);
crate setpos (getpos cratever1_pos);
hint "A";
   };

   case 2:
   {
oficer setpos (getpos ldver2_pos);
crate setpos (getpos cratever2_pos);
hint "B";
   };

};

It should choose A or B pos of oficer and crate, while taking position of game logics called ldver1_pos etc.

I dont know why, cript is not working and shows error: needed script, tyle object.

I dont know what causes this problem, script looks fine to me. Anyone can help?

Share this post


Link to post
Share on other sites

Only one of those cases will ever be true and then only half the time. random 2 gives a number in the range [0;2[ and you floor it thus the result is either 0 or 1. You check for case 1 or 2.

Not sure why you get the error you describe. How do you run the script?

Share this post


Link to post
Share on other sites

Is this in a .sqs file? If so you need to rename to .sqf because A2 will get confused and emit all kinds of odd errors if it sees new-style syntax in old-style files.

Share this post


Link to post
Share on other sites

Like Muzzle said, floor random 2 gives you 0 or 1, not 1 or 2.

Share this post


Link to post
Share on other sites

You can use ceil of you still want to use 1 and 2.

_liczba = ceil (random 2);

Also, what the hell is "liczba?" You should use more descriptive variables.

Share this post


Link to post
Share on other sites

Also, what the hell is "liczba?" You should use more descriptive variables.

He's from Poland, Google translator said it means "number". ;) Still, non-english coding/scripting is just evil.

Share this post


Link to post
Share on other sites

Problem is not solved. Script is in .sqf, I tried both cein and round (shame on me, I forgot to mention). Something is wrong with setpos/getpos, because I receive error either on line 12 or 19, what gives me setpos/getpos commands.

I run the script in the init.sqf:

if ((!isServer) && (player != player)) then
{
 waitUntil {player == player};
};

if (isServer) then
{
//Init UPSMON scritp
ups = call compile preprocessFileLineNumbers "scripts\Init_UPSMON.sqf";	
setviewdistance 1600;
briefing = [] execVM "Briefing.sqf";
intro = [] execVM "Intro.sqf";
crateevent = true;
crate = [] execVM "rollin.sqf";
};



//Process statements stored using setVehicleInit
processInitCommands;

//Finish world initialization before mission is launched. 
finishMissionInit;


if(true) exitWith {}; 

And _liczba is just _number in polish, which should be rolled to locate crate and officer in position A or B, randomly.

EDIT: Checked getmarketpos command and "default" syntax. Still not working.

Edited by SaS TrooP

Share this post


Link to post
Share on other sites

Well sorry to say so but

1. There is nothing wrong with the script itself.

2. If you get the "needed script, tyle object." error then I think I know your problem.

Right this is a suspection now but in your postings you always wrote

The correct english way:

officer

In your script however it says:

oficer

Have you checked that out? Or is it on purpose?

Thus I guess it's just a typo somewhere.

Share this post


Link to post
Share on other sites

Purpose.

I checked all names of markers/game logics (depending what command I've used) and units involved in the script. There is no mistake.

Share this post


Link to post
Share on other sites

What do these two variables stand for ?

ldver1_pos

cratever1_pos

Share this post


Link to post
Share on other sites

I rebuild it.. Went through it with the debug console

Using getpos ldver1_pos

popped up errors.

Instead use

getMarkerPos "gamelogicname";

and it will work.

Share this post


Link to post
Share on other sites

It works fine now, thanks.

But how the hell game logic requires marker-specified command?!

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  

×