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
 

Can someone explain loadstring?

Previous Thread :: Next Thread 
2tallhank is not online. 2tallhank
Joined: 11 Jun 2010
Total Posts: 2075
25 May 2013 04:46 PM
Like what it does?

And maybe give me an example?
Report Abuse
LikeABoss967 is not online. LikeABoss967
Joined: 18 Aug 2012
Total Posts: 95
25 May 2013 04:47 PM
http://wiki.roblox.com/index.php/Tostring#loadstring

expect me
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 May 2013 04:49 PM
It interprets a string as Lua code and returns it as a function.

Example:

local str = "print('hello world')"
local func = loadstring(str)
func()

Or you could could run it outside of a variable:

local str = "print('hello world')"
loadstring(str)()

In either code, the contents of the variable str will be ran as a script, printing "hello world" to the output.
Report Abuse
2tallhank is not online. 2tallhank
Joined: 11 Jun 2010
Total Posts: 2075
25 May 2013 04:52 PM
That makes sense.

What else could you do other than print "hello world"?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 May 2013 04:57 PM
Anything, it doesn't matter--just so long as it can be ran as executable code. The loadstring function actually returns two values, the first being the function, and the second being the error--if there is one. If the code ran successfully, the second returned value will be nil. Example:

local str = "hi"
local func, err = loadstring(str)
print(func, err)

> nil [string "hi"]:1: syntax error near < eof >

Or an example where it runs successfully:

local str = "print('hi')"
local func, err = loadstring(str)
print)(func, err)

> function: 0x1117b80 nil
Report Abuse
2tallhank is not online. 2tallhank
Joined: 11 Jun 2010
Total Posts: 2075
25 May 2013 05:00 PM
Thank you for the information.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 May 2013 05:01 PM
No problem.

http://wiki.roblox.com/index.php/User:ElectricBlaze
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