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

Why wont this terrain generation script work?

Asked by 9 years ago

Here is the script

 function Generate(xz, y)
    y = game.Workspace.BasePlate.Size = Vector3.new(2,30 or 7,35)
    xz = game.Workspace.BasePlate.Size + 212, 21.6, 812 or 234, 21.6, 812
    xyz = y + xz
    print(xyz)
end

Generate(xyz)

Output: Workspace.Generate:2: unexpected symbol near '='

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

There are many problems with this script.

I'm not precisely sure what you were trying to do, but I can begin by making this script work.

 function Generate(xz, y)
    y = game.Workspace.BasePlate.Size = Vector3.new(2,30 or 7,35)
    xz = game.Workspace.BasePlate.Size + 212, 21.6, 812 or 234, 21.6, 812
    xyz = y + xz
    print(xyz)
end

Generate(xyz)

You cannot use or the way you are using it. 30 or 7 is just 30. Probably you are trying to generate a random number between 7 and 30. While we can use math.random directly to do this, it's a bit cumbersome, so let's make our own continuous random number function:

function rand(low,high)
    local random = math.random();
    -- random is a random number between [0, 1]
    random = random * (high - low)
    -- random is a random number between [ low - low, high - low ]
    random = random + low
    -- random is a random number between [low, high]
    return random
end

Now to generate a random number between 7 and 30, we can write rand(7, 30).


You cannot assign y and Size in one line (that wouldn't even make sense!)

You could possibly just mean to use

game.Workspace.BasePlate.Size = Vector3.new(2, rand(7, 30) ,35)

You don't define xyz as you use it on the final line.


To add Vectors (positions and sizes) you need to add vectors, not the components, e.g.,

part.Size = part.Size + Vector3.new( 1 , 2 , 3)
-- Will add 1 to x, 2 to y, and 3 to z of the Part's size

Please significantly revise your code and describe what it is your are trying to do so we can help you more. I'm really at a loss of what you were trying to accomplish, but hopefully these points help you get in the right direction.

0
Why -1 me?:( iluvmaths1123 198 — 9y
0
100% Confusing me iluvmaths1123 198 — 9y
0
Now i get this output:Workspace.Generate:2: attempt to call global 'rand' (a nil value) iluvmaths1123 198 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

function Generate() y = game.Workspace.BasePlate.Size + Vector3.new(game.Workspace.BasePlate.Size.X, 2.30, game.Workspace.BasePlate.Size.Z) or y == game.Workspace.BasePlate.Size + Vector3.new(game.Workspace.BasePlate.Size.X, 7.35, game.Workspace.BasePlate.Size.Z) xz = game.Workspace.BasePlate.Size + Vector3.new(212, 21.6, 812) or xz == game.Workspace.BasePlate.Size + Vector3.new(234, 21.6, 812) xyz = y + xz return xyz end print(Generate())

if you want to make it generate a random sized base plate then you will need to use math.random()

Answer this question