Jump to content
Sign in to follow this  
Arska134

Random not working

Recommended Posts

Ok so i encountered this problem. Here is script:

;Antaa luvun 0-4
_luku = round(random 4)

if (_luku = 0) 
{
_wp = _group addWaypoint [position kohde1, 0]
hint "Joukko lähtee suuntaan kohde1"
}

if (_luku = 1) 
{
_wp = _group addWaypoint [position kohde2, 0]
hint "Joukko lähtee suuntaan kohde2"
}


if (_luku = 2) 
{
_wp = _group addWaypoint [position kohde3, 0]
hint "Joukko lähtee suuntaan kohde3"
}

if (_luku = 3) 
{
_wp = _group addWaypoint [position kohde4, 0]
hint "Joukko lähtee suuntaan kohde4"
}

if (_luku = 4) 
{
_wp = _group addWaypoint [position kohde5, 0]
hint "Joukko lähtee suuntaan kohde5"
}

...and always it's outputting what is inside of last 'if'. "Joukko lähtee suuntaan kohde5"

Share this post


Link to post
Share on other sites

Is that SQS? I don't know SQS, however, based on a quick look on the wiki it looks like you need 'then' before your braces.

Share this post


Link to post
Share on other sites
Is that SQS? I don't know SQS, however, based on a quick look on the wiki it looks like you need 'then' before your braces.

yup. It's sqs, but with 'then', not work neither.

Share this post


Link to post
Share on other sites

"=" isn't used for checking a value, but adding a value to a variable. Use "==" instead, and maybe typical sqs language such as :

? (_luku == 0) :_wp = _group addWaypoint [position kohde1, 0];hint "Joukko lähtee suuntaan kohde1"

Share this post


Link to post
Share on other sites
Oh yeah forgot to mention that thing too:

Comparison it == not =.

Still not working. :/

Share this post


Link to post
Share on other sites

If (...) then {...} does only work in .sqf as i know.

Edit: ProfTournesol´s thing should work.

Share this post


Link to post
Share on other sites

First of all, put -showScriptErrors in your shortcut parameters so that you'll know what the problem is and we don't have to guess.

Second, your syntax is wrong for both sqs and sqf. I assume that you want sqf because you're writing a structured script, so here's an example.

//Antaa luvun 0-4
_luku = round(random 4);

if (_luku == 0) then {
_wp = _group addWaypoint [position kohde1, 0];
hint "Joukko lähtee suuntaan kohde1";
};

Remember to execute sqf with execVM instead of exec.

Finally, here's a more cost effective solution.

_kohteet=[kohde1,kohde2,kohde3,kohde4,kohde5];

//Antaa luvun 0-4
_luku=floor random 5;

_wp=_group addWaypoint [getPos (_kohteet select _luku),0];
hint format ["Joukko lähtee suuntaan kohde%1",_luku+1];

Share this post


Link to post
Share on other sites

Now it's not giving any of those hints.

; Antaa luvun 0-4
; _luku =  round(random 4)

? (_luku == 0) : _wp = _group addWaypoint [position kohde1, 0];hint "Joukko lähtee suuntaan kohde1"
? (_luku == 1) : _wp = _group addWaypoint [position kohde2, 0];hint "Joukko lähtee suuntaan kohde2"
? (_luku == 2) : _wp = _group addWaypoint [position kohde3, 0];hint "Joukko lähtee suuntaan kohde3"
? (_luku == 3) : _wp = _group addWaypoint [position kohde4, 0];hint "Joukko lähtee suuntaan kohde4"
? (_luku == 4) : _wp = _group addWaypoint [position kohde5, 0];hint "Joukko lähtee suuntaan kohde5"

---------- Post added at 07:07 PM ---------- Previous post was at 07:05 PM ----------

First of all, put -showScriptErrors in your shortcut parameters so that you'll know what the problem is and we don't have to guess.

Second, your syntax is wrong for both sqs and sqf. I assume that you want sqf because you're writing a structured script, so here's an example.

//Antaa luvun 0-4
_luku = round(random 4);

if (_luku == 0) then {
_wp = _group addWaypoint [position kohde1, 0];
hint "Joukko lähtee suuntaan kohde1";
};

Remember to execute sqf with execVM instead of exec.

Finally, here's a more cost effective solution.

_kohteet=[kohde1,kohde2,kohde3,kohde4,kohde5];

//Antaa luvun 0-4
_luku=floor random 5;

_wp=_group addWaypoint [getPos (_kohteet select _luku),0];
hint format ["Joukko lähtee suuntaan kohde%1",_luku+1];

Thanks it's now working. :)

Share this post


Link to post
Share on other sites

Of course, you commented the main line using a ";"

; Antaa luvun 0-4
[b][i]_luku =  round(random 4)[/i][/b]
? (_luku == 0) : _wp = _group addWaypoint [position kohde1, 0];hint "Joukko lähtee suuntaan kohde1"
? (_luku == 1) : _wp = _group addWaypoint [position kohde2, 0];hint "Joukko lähtee suuntaan kohde2"
? (_luku == 2) : _wp = _group addWaypoint [position kohde3, 0];hint "Joukko lähtee suuntaan kohde3"
? (_luku == 3) : _wp = _group addWaypoint [position kohde4, 0];hint "Joukko lähtee suuntaan kohde4"
? (_luku == 4) : _wp = _group addWaypoint [position kohde5, 0];hint "Joukko lähtee suuntaan kohde5"

Anyway, sqf is more efficient.

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  

×