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: Attempt to get length of 'items'

Previous Thread :: Next Thread 
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
30 Jun 2015 07:43 PM
So, I have a moduleScript that has this function:

function makeDropDown(button, items)

Everything goes all fine and dandy until we get here:

menu.Size = UDim2.new(1,0,1 * #items,0)

Items is supposed to be a table, but it doesn't like it when I try to put it in the functionality of the function without supplying it an actual value.

Am I screwing up badly?


jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
30 Jun 2015 07:53 PM
b

jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jun 2015 07:56 PM
Try encasing the #items in parentheses. If that doesn't fix it, post the actual output, and the line where you call the function.

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
30 Jun 2015 07:58 PM
Nope, didn't help.

Here's the error log:

20:58:14.532 - ServerScriptService.createDropDown:3: attempt to get length of local 'items' (a nil value)
20:58:14.533 - Stack Begin
20:58:14.533 - Script 'ServerScriptService.createDropDown', Line 3 - global makeDropDown
20:58:14.533 - Script 'ServerScriptService.createDropDown', Line 14
20:58:14.534 - Stack End
20:58:14.534 - Requested module experienced an error while loading
20:58:14.534 - Script 'Players.Player1.PlayerGui.dropDownTest.dropDown.Script', Line 1
20:58:14.535 - Stack End

jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
30 Jun 2015 07:59 PM
You should probably actually use a table as the second argument when calling the function.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jun 2015 08:05 PM
The issue is not on that line, although it may look like it.

The issue is that for some reason, the table that you're passing to the function when you call it doesn't exist. Show us the actual code for the creation of the table and the calling of the function.

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
01 Jul 2015 09:08 AM
There is no making of the table; just an argument.


function makeDropDown(button, items)
local menu = Instance.new("Frame", button)
menu.Size = UDim2.new(1,0,1 * #items,0)
menu.ZIndex = button.ZIndex + 1

for i,v in pairs(items) do
local item = Instance.new("TextButton", menu)
item.Size = UDim2.new(1,0,1 / #items,0)
item.Text = v
item.Position = UDim2.new(0,0,i - 1,0)
end
end

return makeDropDown()


jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
01 Jul 2015 09:34 AM
b

jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
01 Jul 2015 09:37 AM
Show us where you require and call the function please, that is what we really need.
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
01 Jul 2015 09:51 AM
Well, here it is.


local dropDownMaker = require(game.ServerScriptService.createDropDown)
local crapToDisplay = {"Foo", "Hello!", "Paper"}

dropDownMaker(script.Parent, crapToDisplay)



jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
01 Jul 2015 09:56 AM
function makeDropDown(button, items)
print(items)
print(type(items))
print(#items)
local menu = Instance.new("Frame", button)
menu.Size = UDim2.new(1,0,1 * #items,0)
menu.ZIndex = button.ZIndex + 1

for i,v in pairs(items) do
local item = Instance.new("TextButton", menu)
item.Size = UDim2.new(1,0,1 / #items,0)
item.Text = v
item.Position = UDim2.new(0,0,i - 1,0)
end
end

return makeDropDown()



Tell me the output
Report Abuse
StartDeveloping is not online. StartDeveloping
Joined: 16 Feb 2015
Total Posts: 740
01 Jul 2015 10:06 AM
Script:
local module = require(game.ServerScriptService.createDropDown)
local crapToDisplay = {"Foo", "Hello!", "Paper"}

module.makeDropDown(script.Parent, crapToDisplay)

ModuleScript:
local dropDownModule = {}

dropDownModule.makeDropDown = function(button, items)
local menu = Instance.new("Frame", button)
menu.Size = UDim2.new(1,0,1 * #items,0)
--menu.ZIndex = button.ZIndex + 1
for i,v in pairs(items) do
local item = Instance.new("TextButton", menu)
item.Size = UDim2.new(1,0,1 / #items,0)
item.Text = v
item.Position = UDim2.new(0,0,i - 1,0)
end
end

return dropDownModule

All of this is correct, but what the hell is the button size 1 scale on x and y? K. Nevermind. I'm done.

Problems:
return makeDropDown(), do not include ()
return makeDropDown, it's already going to run the function and items is blank.
function? Nah. Use module.createShizzle = function(blah, variable) and call it with module.createShizzle(blah, umg)
The reason why you get "Requested module experienced an error while loading" is because you're module crashed.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
01 Jul 2015 10:25 AM
Yeah, above is right.

Basically remove the parentheses on your return line - you're not calling the function, you're returning the function itself.

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
Astrain1 is not online. Astrain1
Joined: 27 Mar 2013
Total Posts: 18697
01 Jul 2015 06:02 PM
Alright, thank you.

jeb get me the seperatrons | that doesn't stop the fact that your house will no longer resemble a house
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