s0ak 0 Posted April 4, 2007 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
shuko 59 Posted April 4, 2007 <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
crashdome 3 Posted April 4, 2007 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
Väinämöinen 0 Posted April 4, 2007 Here are all rounding options... http://community.bistudio.com/wiki/ceil http://community.bistudio.com/wiki/floor http://community.bistudio.com/wiki/round Share this post Link to post Share on other sites
crashdome 3 Posted April 4, 2007 _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 awesome... I did learn something new. Share this post Link to post Share on other sites
celery 8 Posted April 4, 2007 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
shuko 59 Posted April 4, 2007 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
Väinämöinen 0 Posted April 4, 2007 Yes i was wrong if its below 0.5 it will round it to 0. Â Share this post Link to post Share on other sites
Big Dawg KS 6 Posted April 4, 2007 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
Gecko-KOSB- 0 Posted April 4, 2007 <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
Big Dawg KS 6 Posted April 4, 2007 @ 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
shuko 59 Posted April 5, 2007 @ 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
-)rStrangelove 0 Posted April 5, 2007 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
celery 8 Posted April 5, 2007 @ 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
zyklone 1 Posted April 5, 2007 @ 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
shuko 59 Posted April 5, 2007 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
baddo 0 Posted April 5, 2007 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 doit 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
shuko 59 Posted April 5, 2007 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
baddo 0 Posted April 5, 2007 Yes yes, teach people SQF by all means 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
crashdome 3 Posted April 5, 2007 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
baddo 0 Posted April 5, 2007 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! 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? Cheers. Share this post Link to post Share on other sites