Jump to content
Sign in to follow this  
s0ak

random > 5

Recommended Posts

Hello, how to make to make a random of 5 ?

I succeeded for 3, but for 5 not

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">rand = random 3;

_aa1 = getMarkerPos "aa1";

_aa2 = getMarkerPos "aa2";

_aa3 = getMarkerPos "aa3";

if (rand <=1) then {sh1 setpos _aa1} else {if (rand <=2) then {sh1 setpos _aa2} else {sh1 setpos _aa3}};

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

rand = floor(random 5);

_pos = switch (rand) do {

case 0: { getMarkerPos "aa1" };

case 1: { getMarkerPos "aa2" };

case 2: { getMarkerPos "aa3" };

case 3: { getMarkerPos "aa4" };

case 4: { getMarkerPos "aa5" };

default { getMarkerPos "aa1" };

};

sh1 setpos _pos;

Share this post


Link to post
Share on other sites

Here is a very simple method to utilize random integers (numbers without decimals for you uber-newbies) in an SQF file:

[EDIT] Compressed to add the third and final option of this crazy thread..

Note: the one using Round below will fail if the number rounds down to 0 unless you use a default case statement.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_i = ceil (random 5);

switch (_i) do

{

  case 1: { blah blah... };

  case 2: { blah blah... };

  case 3: { blah blah... };

  case 4: { blah blah... };

  case 5: { blah blah... };

};

Share this post


Link to post
Share on other sites
_i = round (random 5);

switch (_i) do

{

 case 1: { blah blah... };

 case 2: { blah blah... };

 case 3: { blah blah... };

 case 4: { blah blah... };

 case 5: { blah blah... };

};

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

thumbs-up.gif

awesome... I did learn something new.

Share this post


Link to post
Share on other sites

Doesn't round make the randomization unequal and introduce number 0 to the 1-5 range?

Share this post


Link to post
Share on other sites
Doesn't round make the randomization unequal and introduce number 0 to the 1-5 range?

Problem with round in the example above is that. If the random number is between 0 and 0.49999999 it will round it down to 0, which is not included in the switch cases.

EDIT: Using floor or ceil, we eliminate that chance.

Share this post


Link to post
Share on other sites
Doesn't round make the randomization unequal and introduce number 0 to the 1-5 range?

Hence the importance of knowing when to use floor and ceil.

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

rand = floor(random 5);

_pos = switch (rand) do {

case 0: { getMarkerPos "aa1" };

case 1: { getMarkerPos "aa2" };

case 2: { getMarkerPos "aa3" };

case 3: { getMarkerPos "aa4" };

case 4: { getMarkerPos "aa5" };

default { getMarkerPos "aa1" };

};

sh1 setpos _pos;

Thats SQF format i believe though, not SQS....

Share this post


Link to post
Share on other sites
@ April 04 2007,18:31)]
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

rand = floor(random 5);

_pos = switch (rand) do {

case 0: { getMarkerPos "aa1" };

case 1: { getMarkerPos "aa2" };

case 2: { getMarkerPos "aa3" };

case 3: { getMarkerPos "aa4" };

case 4: { getMarkerPos "aa5" };

default { getMarkerPos "aa1" };

};

sh1 setpos _pos;

Thats SQF format i believe though, not SQS....

So, it's not like all control structures are exclusive to one format. I mean if-statements and while loops work in SQS too, why shouldn't switch? SQS scripts can use any of the control structures, just look at the rules for SQS syntax so you know how (ex: all on one line).

Edit: And SQF should be used whenever possible anyway (which now is practically always), it's much better.

Share this post


Link to post
Share on other sites
@ April 05 2007,00:31)]Thats SQF format i believe though, not SQS....

Yes, and SQF is the way to go for ArmA, SQS is in the past.

Share this post


Link to post
Share on other sites

I think it'd be more elegant to calc a random marker if you have a number of markers for placing an object randomly.

You could get indexed markers with the format[] command, collect markers you found in an array and then setpos the object onto a randomly chosen marker via (array select (random (count array - 1))).

Share this post


Link to post
Share on other sites
@ April 05 2007,00:31)]Thats SQF format i believe though, not SQS....

Yes, and SQF is the way to go for ArmA, SQS is in the past.

Why do my missions run like a daydream without a single SQF script to soil their innards?

Share this post


Link to post
Share on other sites
@ April 05 2007,00:31)]Thats SQF format i believe though, not SQS....

Yes, and SQF is the way to go for ArmA, SQS is in the past.

Why do my missions run like a daydream without a single SQF script to soil their innards?

They ofcourse still work.

But they're a maintenance and readability nightmare. But use whatever works for you, if you don't want to learn SQF you don't have to. Yet.

Share this post


Link to post
Share on other sites

Exactly, yet.

From wiki:

"In Armed Assault, the already existing SQF syntax was introduced for scripts. SQS syntax is still usable, but is considered deprecated in Armed Assault."

And there is no point to teach people the old/lesser/whatever way on this forum.

salisan said it already. Even if sqs still work just as good as sqf, its just so messy. Ugh.

Share this post


Link to post
Share on other sites

SQS is messy? That depends on how you write it doesn't it? It surely is not the syntax or commands that you can use that makes scripts messy... it is HOW you use them.

To quote a good old rock'n'roll band:

Quote[/b] ]it ain't what you do, it's how you do

it ain't what you've been through

it's how you've been through

Cheers.

Share this post


Link to post
Share on other sites
SQS is messy? That depends on how you write it doesn't it? It surely is not the syntax or commands that you can use that makes scripts messy... it is HOW you use them.

I give you that, it depends alot on how you do it. "messy" is more like an opinion than a pure fact, at least my poor brain likes to read code that is in a "real code style format", aka how it is in about all real programming languages.

Still, the point is, since there are beginners learning to script here, why teach them the old way? As you said, its the same commands and all. Learning sqf isnt any harder than sqs.

Share this post


Link to post
Share on other sites

Yes yes, teach people SQF by all means smile_o.gif I have absolutely no objections to that.

I agree learning SQF is not any harder than learning SQS, even though many people have said so in the past. I don't understand why they said so, maybe all the ; made them think SQF is closer to some real programming language and not a toy language like SQS...

Share this post


Link to post
Share on other sites

SQF versus SQS isn't down to how it is written and readability (syntax). It goes beyond that. It's the flexibility and control of how it is compiled and ran. It is also about how much more leverage in control structures there are.

If you want the real scoop about why SQS is being phased away, I suggest you start here and rather than ignore the details you don't understand, ask in a new thread...

So, people, can we please not debate SQS vs SQF in a thread about random numbers and simple branching ??

I was shocked to see the # of responses to this thread and I was actually hoping it was a discussion about the topic....

Share this post


Link to post
Share on other sites
If you want the real scoop about why SQS is being phased away, I suggest you start here and rather than ignore the details you don't understand, ask in a new thread...

Thank You very much. So that's where one can learn SQF... Christmas came early this year!

xmas_o.gif

Of course of course, it's not just the syntax and the commands that can be used. I think you missed the most important point: often it does not matter one bit which one you use of these two tools, it is the goal we are trying to achieve that actually matters. Practice against theory etc. etc. that talk you know what I am saying. Some people drive a BMW some people drive a Lada but all are happy, why?

smile_o.gif

Cheers.

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  

×