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 » Scripters
Home Search
 

Re: ModuleScript tables not working properly

Previous Thread :: Next Thread 
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:37 AM
K, so in a module script I have

local D = {}

D.ExampleShapes = {
["Cube"] = {
{50,50,50},{-50,50,50},{-50,50,-50},{50,50,-50},
{50,-50,50},{-50,-50,50},{-50,-50,-50},{50,-50,-50},
["Lines"] = {
{1,2},{2,3},{3,4},{1,4},
{5,6},{6,7},{7,8},{5,8};
};
};
};

D.CreateObject = function(points,canvas)
print(points.ExampleShapes.Cube.Lines) --This is the bug
end;

return D;

-----------then in a localscript I have

local Dim = require(game.ReplicatedStorage.Dimensions);
local Canvas = script.Parent.Canvas;

local Cube = Dim:CreateObject(Dim.ExampleShapes.Cube,Canvas);

It should print "table : LettersAndNumbers", but it just prints nil..
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 11:38 AM
Do you use a generic for loop to go through the table?
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:39 AM
I don't have a for loop anymore. (I used to have more code but now I have to debug >.>)

I had a for _,v in ipairs(points.Lines) do

but it errored saying lines was nil.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:40 AM
local D = {}

D.ExampleShapes = {
["Cube"] = {
{50,50,50},{-50,50,50},{-50,50,-50},{50,50,-50},
{50,-50,50},{-50,-50,50},{-50,-50,-50},{50,-50,-50},
["Lines"] = {
{1,2},{2,3},{3,4},{1,4},
{5,6},{6,7},{7,8},{5,8};
};
};
};

When I just do

print(D.ExampleShapes.Cube.Lines)

it works, but inside the function it does not.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 11:41 AM
Nix what I just said, "points.ExampleShapes.Cube.Lines" may not exist.
Namely the "points" part.

I don't see "points" anywhere in your script.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:42 AM
D.CreateObject = function(points,canvas)
print(points.ExampleShapes.Cube.Lines) --This is the bug
end;

the points is in the function(), its just a variable name.

in the localscript I put the Cube table there.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:43 AM
local Cube = Dim:CreateObject(Dim.ExampleShapes.Cube,Canvas);
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 11:46 AM
Wow I'm blind. My apologies. I'm gonna go into studio and see if I can do something to confirm my suspicions on something regarding this, though.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 11:48 AM
K, I'm thinking it may be a bug with passing tables through module scripts. Maybe it turns the string Id "Lines" into an integer.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:06 PM
It seems I was right, this only occurs with a modulescript.

I compiled lua 5.3 in c++ with visual studio 2015 professional and then ran this.

x = {["cat"] = {5}}
function p(l) print(l["cat"]) end
p(x)
table: 0000003B377BC9C0

As you can see, it worked as expected. Unless this was a bug in 5.1 thats been patched, it has to do with module scripts.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:11 PM
I did a really really basic replication using exactly what you gave me... And it worked? So I'm drawn to assume your error is elsewhere.

Example (Please, test in studio):

http://www.roblox.com/Test-place?id=301921174
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:13 PM
So I can confirm it is not a ModuleScript issue.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:26 PM
Poseidas.

D.CreateObject = function(points,canvas)
print(points.ExampleShapes.Cube.Lines)
end;

is actually supposed to be

D.CreateObject = function(points,canvas)
print(points.Lines)
end;
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:28 PM
Since points is D.ExampleShapes.Cube as it shows in the localscript
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:31 PM
Um... Im a bit confused.

You used

local Cube = Dim:CreateObject(Dim.ExampleShapes.Cube,Canvas);


but yet you did

D.CreateObject = function(points,canvas)
print(points.ExampleShapes.Cube)
end;

Points shouldn't be Dim...
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:32 PM
I copied and pasted YOUR script. So if the table is misarranged, that would be your fault.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:34 PM
I mean I literally made no changes. I was going to, after I confirmed your script didn't work... But it did work, so I'm confused as well.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:36 PM
Now I'm extremely confused.

How can points equal Dim when you typed Dim.ExampleShapes.Cube

I know I messed up when giving you example code, but it should still be impossible to work.

I usually don't give out my full code (Not too long yet), but as this bugs me you can test in edit mode.

http://www.roblox.com/games/301896657/Personal-Testing
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:40 PM
I did print(points.CreateObject) and it printed function. so I can confirm for some reason the variable points is changing to dim.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:42 PM
local Dim = require(game.ReplicatedStorage.Dimensions);
local Canvas = script.Parent.Canvas;

local Cube = Dim:CreateObject(Dim,Canvas);

-----

--[[For best preformance use this with a local script]]--

local D = {};
local RunService = game:GetService("RunService");
local Canvas = nil;
local Rendering,Storage= {},{};
local id = 0;

D.ExampleShapes = {
["Cube"] = {
{50,50,50},{-50,50,50},{-50,50,-50},{50,50,-50},
{50,-50,50},{-50,-50,50},{-50,-50,-50},{50,-50,-50},
["Lines"] = {
{1,2},{2,3},{3,4},{1,4},
{5,6},{6,7},{7,8},{5,8};
};
};
};

D.CreateObject = function(points,canvas)
print(points.ExampleShapes.Cube.Lines)
--Omitted the rest of code in the event you didn't want this bit shared
end;

RunService.Heartbeat:connect(function(Step)
for _,x in ipairs(Rendering) do
for _,v in ipairs(x.Items) do

end;
end;
end);

return D;

-----

Table was printed successfully.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:44 PM
Also, upon reverting it to what you previously gave me in the beginning, the Table ID changed. So I'm assuming it was just returning a blank table (That doesn't technically exist but is still accessible. Because tables can do some funky stuff.)
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:47 PM
Okay things are getting even more trippy.

I changed D.ExampleShapes do _G.ExampleShapes

then in the localscript I did

_G.ExampleShapes.Cube

But it still equals Dim somehow.
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
30 Sep 2015 12:49 PM
Omg... I can't believe I didn't catch this sooner.

Theres no error with roblox modulescripts.

I was using Dim:CreateObject(points,canvas)

I didn't think that it would make Dim the first variable in the function.

Dim.CreateObject(points,canvas) works, you just have to remove the :

Well, thanks anyways. This explains the whole _G thing too.
Report Abuse
Poseidas is not online. Poseidas
Joined: 23 Nov 2008
Total Posts: 2659
30 Sep 2015 12:56 PM
Ha! Who would've thought. Didn't even see that.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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