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 » Scripting Helpers
Home Search
 

Re: %, Literally.

Previous Thread :: Next Thread 
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
19 Apr 2009 04:20 PM
W...T....H....

Why does Roblox keep crashing when I do this?

local a = 5

function foo()
print(%a)
end

foo()

I think it's the %a part, though isn't %a supposed to return a deep copy of it's variable?
Report Abuse
leemo is not online. leemo
Joined: 16 Feb 2008
Total Posts: 6226
19 Apr 2009 04:21 PM
a should be global not local.
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
19 Apr 2009 04:23 PM
local = 5
function foo()
print("%a")
end

You forgot quotes.
Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
19 Apr 2009 04:24 PM
Wouoldn't matter, tested it anyway, still got the crash.
Halp?
Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
19 Apr 2009 04:24 PM
Lol...DingDong, not what I'm trying to do.
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
19 Apr 2009 04:26 PM
Then what are you trying to do? Get a percentage of a?
Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
19 Apr 2009 04:27 PM
Hehe, Silly.


Upvalues were added to work around the function scope limitation. Prefixing an outer-scope variable reference with % produces a copy of that variable as of the function's instantiation. Only the immediate scope containing the function and the global scope may be accessed in this manner.
Since the variable is a copy, it's not possible for the function to alter the original value. A common solution to this problem is to put such variables inside a table and access the table as an upvalue. The table acts as a function closure.

local closure = { a=5 }
local foo = function()
%closure.a = %closure.a + 1
%closure.b = 'hello'
end

Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
19 Apr 2009 04:38 PM
bummped
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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