Main Search
Delta Corp Forum Index
 
 
FAQ Members Groups Profile Private Messages

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact [email protected].
Making Custom Objects by xLegox
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Delta Corp Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
kiddietron
Site Admin


Joined: 06 Feb 2008
Posts: 797
Location: On Roblox

PostPosted: Sun May 11, 2008 1:32 am    Post subject: Making Custom Objects by xLegox Reply with quote

Ever wonder how you can make object with a set of properties like the Roblox ones? Well here's how...

Your data type here will be a "Vector2"

Vector2 = {} --this declares an object of the class "Vector2" (yes, it is a table as well)

function Vector2:new(one, two) --the function that we will use to create new objects of this class
newTB = {x, y} --this makes our new object with the properties, wich you set as objects in the table
newTB.x = one --set the value to the one called in the argument
newTB.y = two
return newTB
end

--now we can call a new object of the class as such...

a = Vector2.new(7, 9)

print(a.x) --> 7

print(a.y) --> 9

a.x = 10

print(a.x) --> 10
------------------------------------------
Quite simple isnt it?

How can you add member (methods, deemed properly) functions to your object though?

-------------------------------------------

function Vector2:new(one, two)
newTB = {x, y}
newTB.x = one
newTB.y = two

function newTB.reset()
newTB.x = 0
newTB.y = 0
end

return newTB
end


a = Vector2.new(5, 7)

print(a.x) --> 5
print(a.y) --> 7

a:reset()

print(a.x) --> 0
print(a.y) --> 0

---------------------------------------------------------

Qute simple again eh?

I haven' yet figured out how to build these into the hierarchy of objects that roblox uses though, so you can't set an objectvalue's value to one of these objects, or make its parent something.

The main purpose of this is to easily work with data in large scripts.
_________________
�Kiddietron
�Phailing at making a signature

Free Money here just sign up and click away.
http://bux.to/?r=kiddietron

Spam is for noobs.



Last edited by kiddietron on Sun May 11, 2008 1:39 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail AIM Address
jtm110972
Beginner Poster


Joined: 06 Feb 2008
Posts: 33
Location: Sitting infront of a laptop

PostPosted: Sun May 11, 2008 1:35 am    Post subject: Reply with quote

Twice, a smiley messed it up...... Shocked
_________________
->jtm110972<-
<a><img></a>
Razz
Back to top
View user's profile Send private message
kiddietron
Site Admin


Joined: 06 Feb 2008
Posts: 797
Location: On Roblox

PostPosted: Sun May 11, 2008 1:39 am    Post subject: Reply with quote

Thanks I fixed it now.
_________________
�Kiddietron
�Phailing at making a signature

Free Money here just sign up and click away.
http://bux.to/?r=kiddietron

Spam is for noobs.

Back to top
View user's profile Send private message Send e-mail AIM Address
SirGelatina
Site Admin


Joined: 01 Mar 2008
Posts: 116
Location: Behind you

PostPosted: Sun May 11, 2008 3:40 am    Post subject: Reply with quote

I used this concept in WitchCraft. The problem of this concept is that #Vector2 return 0, not 2 (Because of x and y properties)
Back to top
View user's profile Send private message Send e-mail MSN Messenger
CyberDonkey
Post-A-Holic


Joined: 06 Feb 2008
Posts: 680
Location: Location: Location:

PostPosted: Sun May 11, 2008 10:26 am    Post subject: Reply with quote

im not good at scripting
but neither am i bad.
though, i haven't learn "TB"
_________________
~CyberDonkey~
~Forever Lame~
Back to top
View user's profile Send private message
chess123mate
Beginner Poster


Joined: 06 Feb 2008
Posts: 40
Location: Canada

PostPosted: Sun Jul 13, 2008 12:53 am    Post subject: Reply with quote

Um... it doesn't work.

It prints out:

7
nil
0
0

Instead of what you said it should:

5
7
0
0

Any explanations?
Back to top
View user's profile Send private message Yahoo Messenger
DingDong272
Avid Poster


Joined: 26 Jun 2008
Posts: 129
Location: United States

PostPosted: Sun Jul 13, 2008 1:43 pm    Post subject: Reply with quote

The arguments get shifted a position. Do this:

print(nil, a.x)
print(nil, a.y)
_________________
.:�ing�ong272:.

.:�elta Corp Avid Poster:.
Back to top
View user's profile Send private message Visit poster's website
chess123mate
Beginner Poster


Joined: 06 Feb 2008
Posts: 40
Location: Canada

PostPosted: Sun Jul 13, 2008 3:10 pm    Post subject: Reply with quote

Then how can this concept be useful at all? You wouldn't know when an argument has been shifted and when it hasn't.
Back to top
View user's profile Send private message Yahoo Messenger
Anaminus
Beginner Poster


Joined: 08 Feb 2008
Posts: 17
Location: Location: Location: Location: Location: Location:

PostPosted: Sun Jul 13, 2008 7:19 pm    Post subject: Reply with quote

This works better:

Code:
Vector2 = {}
function Vector2.new(x,y)
   local object = {x = x, y = y}
   function object:reset()
      self.x = 0
      self.y = 0
   end
   return object
end



?-Anaminus-?
_________________
?-Anaminus-?

^^You're probably seeing this twice because I typed in my signature >_<
Back to top
View user's profile Send private message
DingDong272
Avid Poster


Joined: 26 Jun 2008
Posts: 129
Location: United States

PostPosted: Sun Jul 13, 2008 7:32 pm    Post subject: Reply with quote

I don't see any declaration of, "self," in there.

How is it going to work?

.:�ing�ong272:.
_________________
.:�ing�ong272:.

.:�elta Corp Avid Poster:.
Back to top
View user's profile Send private message Visit poster's website
chess123mate
Beginner Poster


Joined: 06 Feb 2008
Posts: 40
Location: Canada

PostPosted: Sun Jul 13, 2008 9:36 pm    Post subject: Reply with quote

"self" must be a special variable in lua. It works Smile

Thanks!
Back to top
View user's profile Send private message Yahoo Messenger
Anaminus
Beginner Poster


Joined: 08 Feb 2008
Posts: 17
Location: Location: Location: Location: Location: Location:

PostPosted: Mon Jul 14, 2008 2:09 am    Post subject: Reply with quote

self automatically refers to the parent of the member function.


?-Anaminus-?
_________________
?-Anaminus-?

^^You're probably seeing this twice because I typed in my signature >_<
Back to top
View user's profile Send private message
DingDong272
Avid Poster


Joined: 26 Jun 2008
Posts: 129
Location: United States

PostPosted: Mon Jul 14, 2008 1:59 pm    Post subject: Reply with quote

Really? That's pretty cool.
_________________
.:�ing�ong272:.

.:�elta Corp Avid Poster:.
Back to top
View user's profile Send private message Visit poster's website
chess123mate
Beginner Poster


Joined: 06 Feb 2008
Posts: 40
Location: Canada

PostPosted: Mon Jul 14, 2008 9:44 pm    Post subject: Reply with quote

Ah! The main changes necessary were

function name.action()
rather than
function name:action()

And vice-versa for properties; ":" instead of "." for internal functions.
And the use of "self" Smile

Now I can use these things! XD
Thanks again, Anaminus!
Back to top
View user's profile Send private message Yahoo Messenger
DingDong272
Avid Poster


Joined: 26 Jun 2008
Posts: 129
Location: United States

PostPosted: Tue Jul 15, 2008 2:24 am    Post subject: Reply with quote

When deeming a member function, you always want to use a period ( . ), not a colon ( : ), because using a period to call the function might not, "behave," correctly.
_________________
.:�ing�ong272:.

.:�elta Corp Avid Poster:.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Delta Corp Forum Index -> Script Requests All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Back to Top              
Jenova Template © digital-delusion.com
Powered by phpBB © 2001, 2002 phpBB Group



For Support - http://forums.BizHat.com

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!