|
| 18 Jun 2014 06:29 PM |
Is it possible to create our own methods that work on a certain instance?
Like :GetMass()
function part:GetMass()
end
Something like that. |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 06:31 PM |
i think its possible, but y u no use a function like
function changetransparency(part,transparency) if part and transparency then part.Transparency=transparency else print("SCRIPT ERROR: Part or Transparency not defined!") end end |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 09:29 PM |
| I don't know, I just feel like creating a method xd. |
|
|
| Report Abuse |
|
|
| |
|
|
| 18 Jun 2014 10:04 PM |
This is possible, but you're going to need to use some pretty haxy custom environments.
Why do you want to do this? |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 10:17 PM |
Like I said, I just want to know :U. There's no actual reasons; |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Jun 2014 03:42 AM |
| ForumPost:ThrowSpell("Bump") |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Jun 2014 06:48 AM |
| Website.Forum["Scripting Helpers"]["Making a method"]:Bump() |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 06:48 AM |
| I can't make it for an instance, but I can provide an example, one sec. |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 06:59 AM |
This is a snippet from my car simulator that I wrote in standard Lua.
Location = {GetLocalCar = { Gas = function() print("Car moving!") end, Brake = function() print("Car stopped!") end, Reverse = function() print("Car moving backwards...") end } }
function Gas() Location.GetLocalCar:Gas() end
function Brake() Location.GetLocalCar:Brake() end
function Reverse() Location.GetLocalCar:Reverse() end
local speed = 0 |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Jun 2014 08:46 AM |
@OP, it is very possible.
But you need to use a ModuleScript and use some haxy lua to operate it properly. |
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 19 Jun 2014 08:54 AM |
| dhatboiipapi means (I guess) you need to use a sandbox |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 09:17 AM |
well i mean the modulescripts is kinda like a way to declare custom functions as such
http://wiki.roblox.com/index.php?title=Module_scripts
this clear things up |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 09:58 AM |
You can always do a function like this:
function math.add(x,y) if x ~= nil and y ~= nil then --this is just an example return x+y end end
print(math.add(4,3)) -- 7 |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 01:46 PM |
@warspyking You are simply running functions that are members of a table. He wants to run methods for an instance. |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 02:07 PM |
As again. Look at the process of ModuleScript |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 03:18 PM |
Location = {GetLocalCar = { Gas = function() print("Car moving!") end, Brake = function() print("Car stopped!") end, Reverse = function() print("Car moving backwards...") end } }
function Gas() Location.GetLocalCar:Gas() end
function Brake() Location.GetLocalCar:Brake() end
function Reverse() Location.GetLocalCar:Reverse() end
local speed = 0
That's what a method is! -_- |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 03:20 PM |
I am simply telling you that what you are doing is not the desired result he wants.
I am not arguing that functions in tables are not methods. |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 03:22 PM |
| I don't really see how he would be able to do this though. But what I did is nessecary to create methods. |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 03:23 PM |
Haxy methods with environments.
That's how! |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2014 03:30 PM |
| If you think It's so easy, show me :P |
|
|
| Report Abuse |
|
|
| |
|