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: How to use __newindex in this situation?

Previous Thread :: Next Thread 
LarzCaetano is not online. LarzCaetano
Joined: 26 Aug 2015
Total Posts: 280
05 Jun 2016 11:02 AM
Alright, i got this.

local Point=newproxy(true)
do
getmetatable(Point).__index={new=function(p0,p,i)
p0=p0 or Vector2.new()
p=p or Vector2.new()
newPoint=newproxy(true)
getmetatable(newPoint).__index={
p0=p0,
p=p,
i=i,
}
getmetatable(newPoint).__newindex=function(self,i,v)
return rawset(self,key,value)
end
getmetatable(newPoint).__tostring=function() return newPoint.p0..","..newPoint.p..","..newPoint.i end
getmetatable(newPoint).__metatable="This metatable is locked."
return newPoint
end}
end

local a=Point.new(Vector2.new(),Vector2.new(),1)
a.p=Vector2.new(10,0)

Actually, i got an error when trying to set the a.p value.
Could someone help me?
Report Abuse
LarzCaetano is not online. LarzCaetano
Joined: 26 Aug 2015
Total Posts: 280
05 Jun 2016 11:08 AM
Help.
Report Abuse
GoogleAnalytics is not online. GoogleAnalytics
Joined: 08 Aug 2008
Total Posts: 455
05 Jun 2016 11:09 AM
what is code suppose to do ?

https://gist.github.com/Rapptz/11305872
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
05 Jun 2016 11:10 AM
p0,p,andi are in the __index table, in __newindex you're trying to change the one in the regular but you can't do that because it's a userdata.

local tbl = {p0=p0,p=p,i=i}
getmetatable(newPoint).__index=tbl
getmetatable(newPoint).__newindex=function(self,i,v)
tbl[i] = v
end
Report Abuse
GoogleAnalytics is not online. GoogleAnalytics
Joined: 08 Aug 2008
Total Posts: 455
05 Jun 2016 11:12 AM
he is right but what is this code..
Report Abuse
LarzCaetano is not online. LarzCaetano
Joined: 26 Aug 2015
Total Posts: 280
05 Jun 2016 11:13 AM
Really @Flux_Capacitor?
I'm calling "A" as a Point.new(), couldn't i do A.p=Vector2.new(1,1)?
What should i do then?
Report Abuse
LarzCaetano is not online. LarzCaetano
Joined: 26 Aug 2015
Total Posts: 280
05 Jun 2016 11:14 AM
It's a module script.
I'm requiring it from another one and then declaring 'local a'.
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
05 Jun 2016 11:19 AM
I already gave you the solution to fix it
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