|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Sep 2015 11:43 AM |
| local Cube = Dim:CreateObject(Dim.ExampleShapes.Cube,Canvas); |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Sep 2015 12:28 PM |
| Since points is D.ExampleShapes.Cube as it shows in the localscript |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|