UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
|
| 29 Mar 2013 03:06 PM |
I'm trying to cycle through a table and change any numbers within a range. Now it works when the numbers are within a range but numbers outside the range get put in twice.
Output = 100 100 10 10
Scipt: local range = function(n1,n2) local n = nil if n1 > n2 then n = n1 - n2 else n = n2 - n1 end return n end
local checkNumbers = function(t, rng, o, ran) -- t = table, rng = range, o = offset, ran = random local t2 = {} if #t ~= 0 then for i, v in ipairs(t) do for i2, v2 in ipairs(t) do if i ~= i2 and range(v,v2) <= rng then -- range returns a positive integer based on which parameter is higher. if ran then table.insert(t2, math.random(tonumber("-"..o), o)) else table.insert(t2, v2 + o) end else table.insert(t2,v) end end end end print(unpack(t2)) end
local ta = {100,10}
checkNumbers(ta,10,10,true) |
|
|
| Report Abuse |
|
|
UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
| |
|
UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
| |
|
|
| 29 Mar 2013 07:26 PM |
Looking at the code, I see you are doing many things, but I'm not sure what things you need, and what things I can get rid of. The thing about when the output isn't errors, is that it means that there is design problems or that something was not accounted for. Please state these things:
The Project The Purpose The input to this code The constraints on the output of the code (Must be string, table, ext) How the input should affect the output.
I will then make a perfect script for you. Just know that the more you plan, the better your code will be. |
|
|
| Report Abuse |
|
|
UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
|
| 29 Mar 2013 07:48 PM |
| I don't want a script made I want my current script to be fixed. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 08:53 PM |
| We don't know what you want, you have not given us enough information. As I said, GIVE US MORE INFORMATION if you want help. The info needed is above. |
|
|
| Report Abuse |
|
|
UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
|
| 29 Mar 2013 09:18 PM |
I'm trying to cycle through a table and change any numbers within a range. Now it works when the numbers are within a range but numbers outside the range get put in twice. Example:
table = {10,100}
checkNumbers(table)
Output:
10 10 100 100
|
|
|
| Report Abuse |
|
|
UnAdmin
|
  |
| Joined: 10 Jul 2012 |
| Total Posts: 4706 |
|
|
| 29 Mar 2013 09:20 PM |
| Also if you actually read my whole post you would have gotten all that information. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 10:35 PM |
In a given range as in index inside of the table, given range as in two numbers in the table, which is what it looks like you are doing? Here is what I think you should be doing, given the small amount of information you will yield:
local function randomize(Table, MinRange, MaxRange, Offset) local newTable = {} for i = MinRange, MaxRange - MinRange do local number = Table[i] if number and number < MaxRage and number > MinRange then newTable[key] = math.random(-Offset, Offset) end end end |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 10:36 PM |
| Oh, and then at the end "return newTable" |
|
|
| Report Abuse |
|
|