#I get the "stack overflow" error
1 messages · Page 1 of 1 (latest)
use math.random\
Where am I supposed to put "math.random" ?
num1 = math.random(2,4)
Ok, ill try that
I did math.random but I am still getting the "stack overflow" error
well yeah, you call the function within the function with no exit condition
Ok, but how am I supossed to fix it?
well why did you do that in the first place
Well, I am new to scripting so this is how I tought it should be done
Well this is just quite incorrect on a few levels:
- Immediately overwriting the given parameters
- for loop is just wrong (num1 & num2 are going to be used as variables, not their values)
pairswouldn't work on the number you're returning from the function
So lets do this way differently.
If num1 is one range, and num2 is another range, you can just use math.random(<min>, <max>) to get a random number within that range, so you'd just print the sum of two randoms. No loop needed.
Thanks because it works, but I was also planning on making it so every possible combination of numbers within those ranges are going to be calculated and the results are going to be printed out
** You are now Level 1! **
Do a for loop that starts at min and end at max, and nest another one inside there and do the calcs in that loop
I am not getting any errors, but it's printing just a number in the output
I reviewed the document you sent here but in the output the numbers 3 and 8 are being printed out 5 times
Okay, so here you're calculating num1 & num2 in the beginning (once again overwriting the parameters of the function, why are you doing that?) I'm not sure why you're doing this.
The first for goes from 2 - 6
The second only does 2 & 6, as that's what's in the table you give pairs.
The second for loop is still wrong, as you're not going to get what you think you are.
Tables are a set of key, value pairs. In an array-like table, the key is index, the value is the value at that index.
So your second for loop, num1 (which is overwriting the variable) is going to be the key of that list, or index. num2 (also overwriting the original variable) will be 2 & 6.
So it'd be (1, 2) & (2, 6), nothing else.
Where should I put num1 and num2?
What is even the purpose of num1 & num2? They aren't really doing anything.
well, they are the variables that tell the script what is the first and the second number
https://create.roblox.com/docs/luau/functions
But why use them as parameters if you're just going to overwrite them? You do that twice
I did this and its finally working, thanks for the help!