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
|
  |
| Joined: 31 Dec 2008 |
| Total Posts: 295 |
|
| |
|
|
| 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 |
|
|
|
| 05 Jun 2016 10:50 AM |
| your creating it as a method but calling it as a function |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|