|
| 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 |
|
|
|
| 13 Jul 2011 02:22 PM |
| Are you sure this is the script with the error? ._. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 02 May 2010 |
| Total Posts: 2400 |
|
|
| 13 Jul 2011 02:24 PM |
math.random() or math.random(1,large number) |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2011 02:31 PM |
| Why would I do any of those things? Did you even read my post? :P |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 13 Jul 2011 02:33 PM |
1Ra:
a = {} a.b = function(c) print(c) end
b = a.b b("Hai") -->Hai |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
 |
| 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 |
|
|
|
| 13 Jul 2011 04:50 PM |
Are you guys that idiotic? I have no idea what's going on myself, sorry. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
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 |
|
|