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: Numbers being different from what they are?

Previous Thread :: Next Thread 
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 02:22 PM
The length and width arguments of my Generate function print out 10 and 0 every time for some reason, even though I'm putting in different numbers, what am I doing wrong? Assume everything is defined.

ModuleScript Generate function:

function module.Generate(self,length,width,origin,move,walls,holes)
local maze = {}
print("Length: "..length) -- 10, what?
print("Width: "..width) -- 0, lolwat
for x = -length*move/2, length*move/2, move do
for z = -width*move/2, width*move/2, move do
local canwall = true
local plate = self.new(self.Info.Plate)
plate.CFrame = CFrame.new(x,0,z)*origin
plate.Parent = Workspace
if holes and math.random(1,20) > 18 then
plate:Destroy()
canwall = false
else
table.insert(maze,plate)
end
if walls and math.random(1,10) == 5 and CFrame.new(x,2.5,z)*origin ~= Workspace.Controlled.CFrame and canwall then
local wall = self.new(self.Info.Wall)
wall.CFrame = CFrame.new(x,2.5,z)*origin
wall.Parent = Workspace
table.insert(maze,wall)
end
local canwall = true
end
end
setmetatable(maze,{})
getmetatable(maze).__index = {}
getmetatable(maze).__index.Clear = function(self)
for i, v in pairs(self) do
v:Destroy()
self[i] = nil
end
end
return maze
end


Script:

Maze = require(Workspace.Maze)
local maze = Maze:Generate(20,20,mazestart,move,true,true)
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 02:25 PM
Btw, these are not the full Scripts. Full place can be found here:

http://www.roblox.com/Roblox-Plays-Maze-Testing-place?id=58724479
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 02:43 PM
This has stumped me, for reals. WHERE IS THAT 10 AND 0 COMING FROM?
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 03:13 PM
Help, this is weird.
Report Abuse
sycips is not online. sycips
Joined: 21 Mar 2011
Total Posts: 1368
23 Mar 2014 03:17 PM
I'm not going to your place to see the whole script, so just post the whole script here if you want some help, because with this info, I can't help you at all...
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 03:32 PM
I warn you now, they're kinda long. Btw, I'm pretty sure the place is uncopylocked.

ModuleScript:

module = {}

function module.new(info)
local part = Instance.new("Part")
for property, value in pairs(info) do
part[property] = value
end
return part
end

module.Info = {}

module.Info.Plate = {
BrickColor = BrickColor.new("Dark stone grey");
Name = "Plate";
Anchored = true;
FormFactor = "Custom";
Size = Vector3.new(4,1,4);
BottomSurface = "Smooth";
TopSurface = "Smooth"
}

module.Info.Wall = {
BrickColor = BrickColor.new("Dark stone grey");
Name = "Plate";
Anchored = true;
FormFactor = "Custom";
Size = Vector3.new(4,4,4);
BottomSurface = "Smooth";
TopSurface = "Smooth"
}

function module.Generate(self,length,width,origin,move,walls,holes)
local maze = {}
print("Length: "..length)
print("Width: "..width)
for x = -length*move/2+origin.X, length*move/2+origin.X, move do
for z = -width*move/2+origin.Y, width*move/2+origin.Y, move do
local canwall = true
local plate = self.new(self.Info.Plate)
plate.CFrame = CFrame.new(x,0,z)*origin
plate.Parent = Workspace
if holes and math.random(1,20) > 18 then
plate:Destroy()
canwall = false
else
table.insert(maze,plate)
end
if walls and math.random(1,10) == 5 and CFrame.new(x,2.5,z)*origin ~= Workspace.Controlled.CFrame and canwall then
local wall = self.new(self.Info.Wall)
wall.CFrame = CFrame.new(x,2.5,z)*origin
wall.Parent = Workspace
table.insert(maze,wall)
end
local canwall = true
end
end
setmetatable(maze,{})
getmetatable(maze).__index = {}
getmetatable(maze).__index.Clear = function(self)
for i, v in pairs(self) do
v:Destroy()
self[i] = nil
end
end
return maze
end

return module


Script:

move = 4
controlling = Workspace.Controlled
start, mazestart = CFrame.new(0,2.5,0), CFrame.new(0,0,0)
changing = false
communicator = Workspace.Communicator
votechange = setmetatable({},{
__index = {Votes = 0}
})
getmetatable(votechange).__newindex = getmetatable(votechange).__index
directions = {
left = Vector3.new(-move,0,0);
right = Vector3.new(move,0,0);
down = Vector3.new(0,0,move);
up = Vector3.new(0,0,-move)
}
Maze = require(Workspace.Maze)
local maze = Maze:Generate(10,0,mazestart,move,"Grid",true,true)

function communicator.OnServerInvoke(player,want)
if getfenv()[want] then
return getfenv()[want]
end
end

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
if directions[msg] and not changing then
local obstacle, pos = Workspace:FindPartOnRay(Ray.new(controlling.Position,directions[msg]))
local hole, pos = Workspace:FindPartOnRay(Ray.new(controlling.Position+directions[msg],Vector3.new(0,-1000,0)))
if not obstacle and hole then
controlling.BodyPosition.position = controlling.BodyPosition.position+directions[msg]
elseif not hole then
changing = true
controlling.BodyPosition.position = controlling.BodyPosition.position+directions[msg]
wait(0.5)
controlling.BodyPosition.position = controlling.BodyPosition.position+Vector3.new(0,-50,0)
wait(0.5)
controlling.BodyPosition.position = Vector3.new(start.X,start.Y,start.Z)
controlling.CFrame = start
changing = false
end
end
if msg == "change" and not votechange[player.Name] then
votechange.Votes = votechange.Votes + 1
if votechange.Votes > game.Players.NumPlayers/2 then
maze:Clear()
maze = Maze:Generate(math.random(10,20),
0,
mazestart,
move,
math.random(1,4) > 2 and "Grid" or "Straight",
math.random(1,4) > 2 and true or nil,
math.random(1,4) > 2 and true or nil)
controlling.BodyPosition.position = Vector3.new(start.X,start.Y,start.Z)
controlling.CFrame = start
for i, v in pairs(votechange) do
votechange[i] = nil
end
votechange.Votes = 0
end
end
end)
player:LoadCharacter()
repeat wait() until player.Character
player.Character:Destroy()
end)
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 03:35 PM
Oops, typo.

local maze = Maze:Generate(20,20,mazestart,move,true,true)

^ Use this instead for the maze variable
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Mar 2014 03:36 PM
Ummm every time you call Generate the numbers you're inputting are 10 and 0...
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
23 Mar 2014 03:50 PM
Just realized that my script wasn't faulty, it was because my internet connection wouldn't let me save my changes, which is why it would input 10 and 0 every time.
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