2DWorlds Forums
This shall be my first script... - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13)
+--- Thread: This shall be my first script... (/showthread.php?tid=7986)



This shall be my first script... - akiake - 08-13-2011


--i <3 already knowing RBX.lua, i made this in a few seconds, and this is my first script
local deb = false
link(game.World.Button1.Collided, function(nope)
if nope.Name == "Body" and deb == false then
deb = true
game.World.Button1.Color = Color(0,255,0) --green
sleep(1)
dep = false
game.World.Button1.Color = Color(255,0,0) --red
end
end)


RE: This shall be my first script... - Qwertygiy - 08-13-2011

Looks right to me... although you might want to start using [lua] tags.


RE: This shall be my first script... - akiake - 08-13-2011

[lua]--i <3 already knowing RBX.lua, i made this in a few seconds, and this is my first script
local deb = false
link(game.World.Button1.Collided, function(nope)
if nope.Name == "Body" and deb == false then
deb = true
game.World.Button1.Color = Color(0,255,0) --green
sleep(1)
dep = false
game.World.Button1.Color = Color(255,0,0) --red
end
end)[/lua]


RE: This shall be my first script... - Paradox - 08-13-2011

That's one big link statement, I don't think it's supposed to be like that.
Let me try.


[lua]local deb = false
function onCollide(hit)
if hit.Name == "Body" and deb == false then
deb = true
game.World.Button1.Color = Color(0,255,0) --green
sleep(1)
deb = false
game.World.Button1.Color = Color(255,0,0) --red
end
end
link(game.World.Button1.Collided, onCollide)[/lua]

I think that's correct.
By the way, you misspelled "deb = false" and wrote "dep = false" towards the end.


RE: This shall be my first script... - akiake - 08-13-2011

@Paradox


anonymous functions = efficiency