lukasaurus 10 Posted April 9, 2015 I'm just learning, going through some video tutorials. I'm familiar with Python and C#. Some of the syntax in Arma Script makes no sense to me for example, the following should work in my head, but does nothing in game. I cannot figure out why random_task_text = ["pink_task","green_task","yellow_task"];//name of task random_task_target = [pink_task,green_task,yellow_task];//target of task //_random_task = random_task_text call BIS_fnc_selectRandom; //hint _random_task //this works _x = floor (random count random_task_text); //get a random task index //hint str _x //this also works hint random_task_text[_x]; //display the task name On lines 3 and 4, that will select a random string and display it. Line 5 is also working (you can see my code to test it commented out). But line 7 does nothing, when in my mind, it should take the random int generated from line 5 and then display the string in that index. It doesn't. Any help? This function is called random_task.sqf and the init.sqf files runs it. I can get it to do the stuff that I have commented out, but am confused as to why I can't get it to work the way I want. Share this post Link to post Share on other sites
Naiss 28 Posted April 9, 2015 the reason why your hint wont pup up or why it wont select random there is because you are using _x, _x is for other stuff like where you use the foreach command. so rename the _x var to something else and it should work Share this post Link to post Share on other sites
2nd ranger 282 Posted April 9, 2015 (edited) hint random_task_text[_x]; is nonsense. What you want to do is: _randomText = random_task_text select (floor random (count random_task_text)); hint str _randomText; select Also, as noted above, don't use _x as a variable, since it is the magic variable used to reference the current element in a forEach statement, for example: {hint str _x; sleep 1;} forEach ["pink_task","green_task","yellow_task"]; ... where each string would be displayed in a hint every 1 second. And if you're not using it already, enable showScriptErrors via the startup parameters. Edited April 9, 2015 by 2nd Ranger Share this post Link to post Share on other sites
lukasaurus 10 Posted April 9, 2015 hint random_task_text[_x]; is nonsense. What you want to do is: What I am wanting to do is get the index value and then use it for multiple arrays. How would I do that? I understand what you did, but that won't give me the index of the string, so I can't use it for other arrays... Share this post Link to post Share on other sites
2nd ranger 282 Posted April 9, 2015 (edited) Oh, I see. Well in that case, just what you had originally, but not using _x as the variable. _int = (floor random (count random_task_text)); And then to use that to select a string and then the corresponding target: _text = random_task_text select _int; _target = random_task_target select _int; hint str _text; //---display the text Edited April 9, 2015 by 2nd Ranger Share this post Link to post Share on other sites
Larrow 2820 Posted April 9, 2015 (edited) Either (as 2nd Ranger has shown above) by getting a random index then using this to select from both lists/arrays. task_texts = [ "pink_task", "green_task", "yellow_task" ]; task_targets = [ pink_task, green_task, yellow_task ]; _random_index = floor ( random ( count task_texts )); _random_task_text = task_texts select _random_index; _random_task_target = task_targets select _random_index; hint format [ "Selected Task\n%1\n\nTasks Target\n%2", _random_task_text, _random_task_target ]; Or if you already have a selected index and you need to find the corresponding index from another list/array use FIND //name of tasks task_texts = [ "pink_task", "green_task", "yellow_task" ]; //target of tasks task_targets = [ pink_task, green_task, yellow_task ]; //Get a random task text _random_task_text = task_texts call BIS_fnc_selectRandom; //Find index of random task test _random_task_index = task_texts find _random_task_text; //Select corresponding task target of select random task text _random_task_target = task_targets select _random_task_index; hint format [ "Selected Task\n%1\n\nTasks Target\n%2", _random_task_text, _random_task_target ]; Edited April 9, 2015 by Larrow corrected missspelt variable Share this post Link to post Share on other sites
killzone_kid 1330 Posted April 9, 2015 -showScriptErrors Share this post Link to post Share on other sites
GieNkoV 30 Posted April 9, 2015 Better call Saul BIS_fnc_selectRandom. Share this post Link to post Share on other sites
lukasaurus 10 Posted April 9, 2015 Oh, I see. Well in that case, just what you had originally, but not using _x as the variable. _int = (floor random (count random_task_text)); And then to use that to select a string and then the corresponding target: _text = random_task_text select _int; _target = random_task_target select _int; hint str _text; //---display the text Alright, I get it, cheers. That's completely unlike any other programming language I've used before with accessing array indexes, which is why I was getting so confused. Share this post Link to post Share on other sites