generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Simple script with funky output

Previous Thread :: Next Thread 
UnAdmin is not online. 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 is not online. UnAdmin
Joined: 10 Jul 2012
Total Posts: 4706
29 Mar 2013 04:01 PM
Bump
Report Abuse
UnAdmin is not online. UnAdmin
Joined: 10 Jul 2012
Total Posts: 4706
29 Mar 2013 07:16 PM
Bump
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
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 is not online. 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
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
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 is not online. 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 is not online. 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
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
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
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
29 Mar 2013 10:36 PM
Oh, and then at the end "return newTable"
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image