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
 

Script Help

Previous Thread :: Next Thread 
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
16 Oct 2011 11:28 AM
I was wondering how to script Lua. The annoying thing is, the wiki only tells us about the workspace and things like that. I am familiar with other languages so this shouldn't be too hard.

Here are some random questions:

Do I need to initiate any classes before doing a script?

What kind of braces do you use in lua? {} () <>

Are there for loops?

What's the random statement?

Can I import classes?

Is lua case sensetive?

I wanted to start off by figuring out how to do a random map change. Let's say I have three maps, would I do it this way? The maps would be in lighting then put in workspace each map is a model.

var maps = random(1)+3

if(maps==1)
{
map1 = Workspace
}
else
if(maps==2)
{
map2 = Workspace
}
else
if(maps==3)
{
map3 = Workspace
}
}
Report Abuse
TigerBloodd is not online. TigerBloodd
Joined: 24 Oct 2010
Total Posts: 2430
16 Oct 2011 11:31 AM
local maps = game.Lighting:GetChildren()
maps[math.random(1,#maps)].Parent = workspace

TigerBloodd | Programmer | Developer
Report Abuse
skipperguy12 is not online. skipperguy12
Joined: 09 Oct 2009
Total Posts: 955
16 Oct 2011 11:34 AM
while true do
wait() -- This one is for making sure the loop actually works, and the map loads.
-- Lets get to cloning! :D

game.Lighting.Mapchange.Map1:clone().Parent = game.Workspace

wait(180) -- Time until the next map .

local m = Instance.new("Message")
m.Parent = game.Workspace
m.Text = "Loading: Map2"
game.Workspace.Map1:remove()


wait(5) -- Just a wait...
m:Remove -- We removed the message from existence after 5 seconds.

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

wait() -- This one is for making sure the loop actually works, and the map loads.
-- Lets get to cloning! :D

game.Lighting.Mapchange.Map2:clone().Parent = game.Workspace

wait(180) -- Time until the next map .

local m = Instance.new("Message")
m.Parent = game.Workspace
m.Text = "Loading: Map1"
game.Workspace.Map2:remove()


wait(5) -- Just a wait...
m:Remove -- We removed the message from existence after 5 seconds.
Report Abuse
skipperguy12 is not online. skipperguy12
Joined: 09 Oct 2009
Total Posts: 955
16 Oct 2011 11:35 AM
Whops. FOrgot theres an end at the end i'm missing.
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
16 Oct 2011 11:57 AM
Tables are {}
Yes, LUA is cAsESenSItIvE, EX: game.Workspace:GetChilder, game.Lighting:GetChildren, part.Parent:findFirsrtChild("Humanoid")
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
16 Oct 2011 12:01 PM
Because obviously no one here knows what Lua is, I'll answer your questions:

"Do I need to initiate any classes before doing a script?"
No, Lua is not Object-Oriented.
print("Hello World")
is the Hello World program.

"What kind of braces do you use in lua? {} () <>"
{} are used as braces, but when passing function parameters, etc., you use ()—like other languages.

"Are there for loops?"
Yes, there are two types.
Numeric for loops:
for i = start, number-to-reach, increment, do --stuff end
for i = 1, 3, 2 do
print(i)
end
will print to the output 1 & 3.

Generic for loops:
for x in iterator_function() do
--stuff (-- is one-line comments, --[[is multi-line comment, ending with ]])
end

I'd recommend looking at this so generic for loops make more sense:
http://wiki.roblox.com/index.php/Generic_for

"What's the random statement?"
I'm not sure what you mean, but math.random() generates a random number, and math.randomseed(seed) seeds the random number generator.
http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions

"Can I import classes?"
Lua doesn't have classes, but you can use Lua tables, which are very different from almost every other language.
http://wiki.roblox.com/index.php/Tables
http://wiki.roblox.com/index.php/Function_Dump/Table_Manipulation


"Is lua case sensetive?"
Yes.

"I wanted to start off by figuring out how to do a random map change. Let's say I have three maps, would I do it this way? The maps would be in lighting then put in workspace each map is a model."

maps = {game.Lighting.Map1, game.Lighting.Map2, game.Lighting.Map3} -- Brackets for tables
maps[math.random(#maps)]:Clone().Parent = game.Workspace
What that line does is select a map from the table maps (maps[]), based on a random number from 1 to the number of maps (math.random(#maps)), clone it (:Clone(), so there's still a copy in Lighting), then make the Parent of the clone (.Parent—the object the map is inside) in workspace (= game.Workspace). Also, Lua is not whitespace-sensitive.
You do not use brackets for if...then statements. Let me show you an example of an if statement:

a = 2
if a == 2 then -- Double equal, the "then" is required.
print(a)
end -- Close the block
if a==3 then
print(a)
end

Before you start out with RBX.lua, I'd recommend learning just Lua. You can go to lua.org/pil if you want, and if you have questions you can look on wiki.roblox.com or in this forum.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
16 Oct 2011 12:02 PM
Oh yeah, feel free to PM me any Lua-related questions. (Not RBX.lua, though—that language changes too quickly and is ultimately horrible).
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
16 Oct 2011 03:50 PM
Thanks Merlin! Can you reference me any online tutorials?
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
16 Oct 2011 04:21 PM
Because Lua is not a very well-known language, there aren't very many. Personally, I'd recommend lua.org/pil—it's easy to understand (especially for someone who has learned other languages) and everything in it is true. It was written by the people who made Lua. If that tutorial doesn't float your boat, then I'm sure you can look up another tutorial.
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
16 Oct 2011 04:23 PM
wat about mien


wiki.roblox.com/index.php/User:Crazypotato4/Test

it has barely even gotten to the part about workspace and stuff
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
16 Oct 2011 04:24 PM
I can't even open that page D:<
*Stabs wiki*
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
16 Oct 2011 04:25 PM
wat

wai

does it give you error

D:

your userpage gives me an error lol
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
16 Oct 2011 04:27 PM
Yeah, it does D:
Telamon is looking into it (ahahaha).
Report Abuse
AverageForumTrollJr is not online. AverageForumTrollJr
Joined: 14 Apr 2011
Total Posts: 182
16 Oct 2011 05:38 PM
http://wiki.roblox.com/index.php/Tutorials

Click on the Button that says "Scripting Tutorials"
Since you have previous programming knowledge (Java?), you should be able to just skim over some of the articles, and just pay attention to the syntax.


-----


"Do I need to initiate any classes before doing a script?"
Lua is not object oriented, so there are no classes. In RBX.Lua, everything you need is already loaded into the interpreter

"What kind of braces do you use in lua? {} () <>"
{} is used for table (Lua's version of an array)
() Only used for defining a function (arguments/parameters) and for calling functions.
<> isn't used
[] is used for accessing an index of a table

"What's the random statement?"
math.random(min, max)
That generates a random number between the range [min] and [max], inclusive.

"Can I import classes?"
In regular lua, you can with the require function.

Is lua case sensetive?
Yes.




~ AFT, wrongfully banned ~
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
18 Oct 2011 01:15 PM
How'd you figure out I programmed java? That was my primary language.

:D

Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
18 Oct 2011 01:27 PM
Can I make Procedures like in Pascal, or the methods in Java?
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
18 Oct 2011 02:56 PM
function f(stringToPrint)
print(stringToPrint)
end

f()

I'd recommend looking at this page:
http://wiki.roblox.com/index.php/Variables
because in Lua, functions are variables, so everything on that page is applicable. (Even x = function())
and
http://wiki.roblox.com/index.php/Functions#Event_Triggered_Functions
because that gives some more stuff on just functions.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
05 Nov 2011 11:44 AM
I'm currently making an RPG that you crash on a planet, etc. I wanted to figure out how to make a movie of the place by using perspectives, how would I do that? I've seen it on games before and want to try it. I've worked with 3D material with things like anim8or and gamemaker and I was wondering how this is done via roblox.
Report Abuse
pokelord910 is not online. pokelord910
Joined: 26 May 2009
Total Posts: 1045
05 Nov 2011 11:49 AM
@k00l Camera, im still learning that as we speak for movies but search it in the wiki to learn. You'll probably have to script animation paths for full movies though, it may be easier to design a comic-like set of decals to describe the rocket crashing etc.

@merlin
http://www.roblox.com/DingDong272s-tutorials-the-full-set-item?id=61167260
tye helped me and quite a few others a lot
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
05 Nov 2011 12:17 PM
NO

NOT THAT

THIS

http://wiki.roblox.com/index.php/Scripting_Book
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
06 Nov 2011 12:01 AM
@Merlin

the random generator is actually math.randomseed(tick())
Report Abuse
snakevenomus is not online. snakevenomus
Joined: 28 Jun 2010
Total Posts: 690
06 Nov 2011 12:27 AM
but wasent mesh making banned?
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
06 Nov 2011 12:30 AM
the amount of stupidity on this thread (which warrants actual intelligent answers) amazes me.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
08 Nov 2011 05:43 PM

Thanks for your help!
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
01 Dec 2011 06:39 PM
Can someone help me with this script? I put this script in an NPC's dialog. I'm not a very good scripter and want to know what's wrong with this code. I suspect I need to make a screengui as a parent of the frame. The point of the script was, when the dialog ends, the screen blacks out by making a frame increase its transparency. And by the way, how do I check if a dialog choice is in use?

if(game.Workspace.OldWeirdPerson.Torso.Dialog.InUse = true)
then
local blackout = Instance.new("Frame")
blackout.Position = UDim2.new(0, 0, 0, 0)
blackout.Size = UDim2.new(1, 1, 1, 1)
local count = 0
while (count<10)
count = count+0.1
blackout.Transparency = UDim2.new(count)
wait 0.1
end
end

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