Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

These values shouldn't be nil?

Asked by 5 years ago
Edited 5 years ago

So I have a ModuleScript that stores various stuff, such as the terrain data.

local DimStats = --- PROCEDURALLY GENERATED DIMENSION DATA ---

{

MainMaterial = nil, -- Main material of dimension's terrain
MaterialVar1 = nil, -- Second material of dimension's terrain
MaterialVar2 = nil, -- Third material of dimension's terrain
MaterialMod1 = false, -- Terrain modifier (material 1)
MaterialMod2 = false, -- Terrain modifier (material 2)

BaseHeight = 32, -- Perlin height mod
BasePower = 16, -- Base perlin power
ChunkScale = 1, -- Chunk scale
RenderDist = 120, -- Render distance
xScale = 80, -- Stretch X-val of chunks over this scale
zScale = 80, --  Stretch Z-val of chunks over this scale

PerlinMod1 = 1, -- Perlin mod 1
PerlinMod2 = 0.25, -- Perlin mod 2
PerlinMod3 = 4, -- Perlin mod 3
PerlinMod4 = 0.5, -- Perlin mod 4

Seed = 0 -- Terrain seed

}

return DimStats

It's just the data for procedural terrain generation. No biggie. What's important to me is the MainMaterial and MaterialVar variables.

I have a script inside said ModuleScript that alters these values:

local DimensionData = require(script.Parent)
local RNG = Random.new()

local FullMaterials = 
{
    Enum.Material.Ground,
    Enum.Material.CrackedLava,
    Enum.Material.Ice,
    Enum.Material.Limestone,
    Enum.Material.Mud,
    Enum.Material.Basalt,
    Enum.Material.Asphalt,
    Enum.Material.LeafyGrass,
    Enum.Material.Salt,
    Enum.Material.Slate,
    Enum.Material.Sand,
    Enum.Material.Sandstone,
    Enum.Material.Grass,
    Enum.Material.Rock,
    Enum.Material.Glacier,
    Enum.Material.Snow
}

local VarMaterials = 
{
    Enum.Material.Ground,
    Enum.Material.CrackedLava,
    Enum.Material.LeafyGrass,
    Enum.Material.Ice,
    Enum.Material.Rock,
    Enum.Material.Slate,
    Enum.Material.Glacier,
    Enum.Material.Sand,
    Enum.Material.Snow,
    Enum.Material.Sandstone,
    Enum.Material.Air,
    Enum.Material.Water
}

DimensionData.MainMaterial = FullMaterials[RNG:NextInteger(1, #FullMaterials)]
DimensionData.MaterialVar1 = VarMaterials[RNG:NextInteger(1, #VarMaterials)]
DimensionData.MaterialVar2 = VarMaterials[RNG:NextInteger(1, #VarMaterials)]

if RNG:NextNumber() >= .33 then DimensionData.MaterialMod1 = true end
if DimensionData.MaterialMod1 and RNG:NextNumber() >= .66 then          DimensionData.MaterialMod2 = false end

The rest of the script shouldn't be relevant, but I can edit this post to include it if needed. Anyways, when I try to grab this data from a normal script, it says that MainMaterial and MaterialVars 1 and 2 are nil, or that one of them is nil... it's weird, because in a script like this...

local RNG = Random.new()

local FullMaterials = 
{
    Enum.Material.Ground,
    Enum.Material.CrackedLava,
    Enum.Material.Ice,
    Enum.Material.Limestone,
    Enum.Material.Mud,
    Enum.Material.Basalt,
    Enum.Material.Asphalt,
    Enum.Material.LeafyGrass,
    Enum.Material.Salt,
    Enum.Material.Slate,
    Enum.Material.Sand,
    Enum.Material.Sandstone,
    Enum.Material.Grass,
    Enum.Material.Rock,
    Enum.Material.Glacier,
    Enum.Material.Snow
}

print(FullMaterials[RNG:NextInteger(1, #FullMaterials)])

...it always returns one of those materials with no problem. Is there something I'm not understanding here? I'm pretty sure ALL THREE of those materials should be defined.

0
what's dimensiondata supposed to be User#22604 1 — 5y
0
The require for the module script, my bad. negativize 0 — 5y

Answer this question