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: An error

Previous Thread :: Next Thread 
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 02:20 PM
I have searched through this, and I cannot tell why I am getting this error.

My error:

Workspace.Script:1: attempt to index field '?' (a nil value)

My code:

local random = math.random
local randomseed = math.randomseed

local rand = function(high)
high = high or 100
randomseed(tick())
return (random(0, high * 100) / 100)
end

local interpolate = function(x, y, z)
local r = rand(1)
return (((x + y + z) / 3) * r)
end

local terrain = function(x, y)
local terra = {}
for i = 1, x do
terra[i] = terra[i] or {}
for j = 1, y do
terra[i][j] = terra[i][j] or {}
terra[i][j] = interpolate(rand(), terra[i - 1][j] or rand(), terra[i][j - 1] or rand())
end
end
end

local ter = terrain(100, 100)

for i, v in ipairs(ter) do
for j, w in ipairs(v) do
print(v .. ", ")
end
print('\n')
end
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
13 Jul 2011 02:22 PM
Are you sure this is the script with the error? ._.
Report Abuse
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 02:23 PM
I am almost certain, because I just ran it, and it didn't work, and I copied and pasted it into the post.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
13 Jul 2011 02:24 PM
Then why not use Ctrl+H and replace random with math.random? I don't think that would kill you. ._.
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
13 Jul 2011 02:24 PM
math.random()
or math.random(1,large number)
Report Abuse
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 02:31 PM
Why would I do any of those things? Did you even read my post? :P
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
13 Jul 2011 02:32 PM
at line 1 u wrote
local random = math.random

try
local random = math.random()
Report Abuse
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 02:33 PM
Did you even read my script? I'm getting a local version of the math.random version so it goes faster, NOT what math.random returns. THE FUNCTION ITSELF. :P
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
13 Jul 2011 02:33 PM
1Ra:

a = {}
a.b = function(c)
print(c)
end

b = a.b
b("Hai") -->Hai
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
13 Jul 2011 02:48 PM
I believe the game is confused because it doesn't have a set field for functions to be saved as. I'm probably wrong; sorry I can't help.
Report Abuse
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 03:14 PM
bump?
Report Abuse
kornawe is not online. kornawe
Joined: 25 Nov 2008
Total Posts: 1272
13 Jul 2011 03:16 PM
you need to have something in the randoms

math.random()
Report Abuse
bunnybunn264 is not online. bunnybunn264
Joined: 04 Oct 2010
Total Posts: 5409
13 Jul 2011 03:18 PM
Explain why? Here, for the last time,

I'M GETTING A LOCAL VERSION OF THE FUNCTION, NOT A RANDOM NUMBER, on line 1.
Report Abuse
dekkonot is not online. dekkonot
Joined: 22 Dec 2010
Total Posts: 6685
13 Jul 2011 04:08 PM
idea, make your own random number maker. Then, math["random"] = nil
table.insert(math, FunctionHere)
Report Abuse
burgly is not online. burgly
Top 100 Poster
Joined: 20 Aug 2006
Total Posts: 2843
13 Jul 2011 04:47 PM
Maybe math isn't fully loaded yet?
[In the sense that math is loaded, but random isn't?]
Report Abuse
PersistentData is not online. PersistentData
Joined: 04 Apr 2011
Total Posts: 6224
13 Jul 2011 04:50 PM
Are you guys that idiotic?
I have no idea what's going on myself, sorry.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
13 Jul 2011 05:40 PM
[ Content Deleted ]
Report Abuse
Apocalyps is not online. Apocalyps
Joined: 15 Feb 2009
Total Posts: 816
13 Jul 2011 06:13 PM
I think its because of this part:

local terrain = function(x, y)
local terra = {}
for i = 1, x do
terra[i] = terra[i] or {}
for j = 1, y do
terra[i][j] = terra[i][j] or {}
terra[i][j] = interpolate(rand(), terra[i - 1][j] or rand(), terra[i][j - 1] or rand())
end
end
end

You are trying to acces 'terra[i - 1][j]' but when i is 1 it will try to acces terra[0][j]
But terra[0] has never been asigned so when you try to index [j] it will give you the error.
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