Trying to get 3 outcomes at once

I am currently trying to get 3 different outcomes out of a table using one function.

I have tried this :

For some reason, when I try to iterate or read off the table there would only be 1 random outcome and not 3.

Could someone kindly tell me what I am doing wrong in order to make it generate 3 outcomes?

EDIT : Where would I need to use the ‘outcomes’ parameter to make it generate 3 outcomes?

Quick question, where is the outcomes parameter being used? I see that you passed in 3, but the value doesn’t seem to be utilized anywhere.

1 Like

yeah, that’s true.
I am not familiar with using parameters. Would you by any chance know where to use it please?

Since you wanted 3 outcomes, I’d assume you should call “FindNewChoice()” in a loop which runs outcomes amount of times.

1 Like

Would I be able to keep the :
‘For i = 1, outcomes do’ loop in the ‘getOutcomes’ function?

You could simply do:

for i = 1, outcomes do

Also, the return statement in the function is unnecessary


Hmm I will try that out, Thank you!

As an alternative i believe you could use this function to get three (given amount) outcomes, as well:
( other options/recommendations in this topic should work)

function GetOutComes(NumberOfOutcomes, Choices) ----Amount, Table of Choices
local ChosenValues = {}

for i = 1, NumberOfOutcomes do
local value = Choices[math.random(1, #Choices)]
while  table.find(ChosenValues, value)  do --If we can find the random value then get another random value, if we cant end the loop and add it to the used table
   value = Choices[math.random(1, #Choices)]	

table.insert(ChosenValues, value)	
	return Outcomes
1 Like

You could use something along the lines of this (this is a rough idea, some editing would need to be used)

repeat wait()
number1,number2,number3 = math.random(1,#choices),math.random(1,#choices),math.random(1,#choices)
until (number1 ~= number2) and (number1 ~= number3) and (number2 ~= number3)

You can then use this to identify the choices by using:


Again; this isn’t a proper solution, just one to get you on the right track.

1 Like

For what I’ve seen in your code, I think you are trying to get three random outcomes from an array, without repeating. You used an array to store choices that are already picked. You should delete the choice from the choice array

Here’s the code for what you are trying to do (if I understood you correctly)

function getOutcomes(choices, outcomes)
    local gotOutcomes = {}
    for i = 1, #outcomes do
        local pickedNum = math.random(1, #choices)
        table.insert(gotOutcomes, choices[pickedNum])
        table.remove(choices, pickedNum)
    return gotOutcomes