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: Weird Module Script Behaviour

Previous Thread :: Next Thread 
eqis is not online. eqis
Joined: 31 Dec 2008
Total Posts: 295
05 Jun 2016 10:27 AM
As the title suggests, my module script is behaving strangely. I attempt to pass in a few arguments to a function and the arguments are 'offset' to the left. For example,

function module:Example(para1, para2)
do stuff
end

require(modulescript).Example(10, 20)

Instead of para1 becoming 10 and para2 becoming 20, para1 becomes 20 and para2 is nil.

Original code:

function module:SetData(dataItem, value)
local stats = player:FindFirstChild("Stats")
if stats ~= nil and stats:FindFirstChild(dataItem) then
stats[dataItem].Value = type(value) ~= "function" and value or value()
elseif stats == nil then
CreatePlayer()
module:SetData(dataItem, value)
elseif not stats:FindFirstChild(dataItem) then
print(value)
local newItem = Instance.new(types[type(type(value) ~= "function" and value or value())], stats)
newItem.Name = dataItem
newItem.Value = value
end
end
Report Abuse
eqis is not online. eqis
Joined: 31 Dec 2008
Total Posts: 295
05 Jun 2016 10:49 AM
Bump.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
05 Jun 2016 10:50 AM
Because you're using a colon in one place, and a period in the other. The colon is only used for object-oriented stuff. If you don't know what that is, then don't bother using it when you make functions.


Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
05 Jun 2016 10:50 AM
your creating it as a method but calling it as a function
Report Abuse
eqis is not online. eqis
Joined: 31 Dec 2008
Total Posts: 295
05 Jun 2016 11:03 AM
Ah, thanks. Have you heard of learning from mistakes Jarod?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
05 Jun 2016 11:09 AM
I didn't mean to come off as irritable or rude, I'm just saying it's something that won't be very useful for a while. It's not something you really need to know in Roblox.


Report Abuse
eqis is not online. eqis
Joined: 31 Dec 2008
Total Posts: 295
05 Jun 2016 11:14 AM
Apologies if I saw it that way. It might be useful for something I'm starting in an hour or so.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
05 Jun 2016 11:40 AM
If you do want to learn, you can do that here. I haven't read it yet, but it should get you started.
http://wiki.roblox.com/index.php?title=Object-Oriented_Programming

For the record, Roblox itself uses OOP (Not in Lua), notably the Instances and such. Those are all Objects.


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