2DWorlds Forums
Are scripts functioning yet? - 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: Are scripts functioning yet? (/showthread.php?tid=1066)

Pages: 1 2


Are scripts functioning yet? - Intile - 10-11-2010

If so, could I get just a couple of examples of something to get started on? From what I can gather, it looks like this'll be using Java instead of Lua, so I'll have to learn an entirely new language. haha.


RE: Are scripts functioning yet? - Jacob__mybb_import1 - 10-11-2010

I use Lua for the scripting. You can type in the command bar, or use Edit>Insert Script to add a script, double click to edit it, then right click>Run Script to test it.

Events don't work yet, but you can do a lot of simple things.

Code:
p =  create("Box"); p. Size = Vec2D(10, 10); p.Position = game.Camera.Position; p.Parent = game.World
[/code]
Code:
while true do game.World.Ground.Color = Color(math.random(0, 255), math.random(0, 255), math.random(0, 255)); sleep(1); end

Code:
step = 0.5
while true do
game.Camera.ScaleFactor = game.Camera.ScaleFactor + step
if game.Camera.ScaleFactor > 16 then
step = -0.5
end
if game.Camera.ScaleFactor < 1 then
step = 0.5
end
sleep(0.05)
end

Code:
game.TaskScheduler:schedule(function() --This makes sure the simulation won't step in the middle of the script
p1 = create("Box")
p1.Position = game.Camera.Position
p1.Parent = game.World

p2 = create("Box")
p2.Position = Vec2D(game.Camera.Position.x, game.Camera.Position.y + 2)
p2.Parent = game.World

w = create("Hinge")
w.Part1 = p1
w.Part2 = p2
w.Anchor = game.Camera.Position
w.Parent = game.JointsService
end)



RE: Are scripts functioning yet? - Intile - 10-11-2010

oh god thank you.
I'm going to experiment around a bit more now that I know this. I'll post a bit later once I make something really silly.


RE: Are scripts functioning yet? - ptown2 - 10-12-2010

oh goodie, now i can make waffle runners 2d mode


RE: Are scripts functioning yet? - Jacob__mybb_import1 - 10-14-2010

Here is a simple script, used in the "Raining parts" game[/code]:
Code:
while true do
p = create("Box");
p.Position = Vec2D(math.random(450, 550), 100)
p.Size = Vec2D(math.random(5, 20), math.random(5, 20))
p.Color = Color(math.random(0, 255), math.random(0, 255), math.random(0, 255))
p.Parent = game.World
s = create("Script")
s.Source = "sleep(5); while script.Parent.Transparency < 1 do script.Parent.Transparency = script.Parent.Transparency + 0.2; sleep(0.1); end; script.Parent:remove();"
s.Parent = p
sleep(1)
end



RE: Are scripts functioning yet? - ptown2 - 10-14-2010

are there ways to make the script run when a player/object appears or dissapears?

like the connection in RBLX LUA?


RE: Are scripts functioning yet? - Jacob__mybb_import1 - 10-15-2010

Like an onChildAdded/onChildRemoved event? I just added events, so it should be pretty easy to do.


RE: Are scripts functioning yet? - Jacob__mybb_import1 - 10-15-2010

The latest version has ChildAdded and ChildRemoved events.


RE: Are scripts functioning yet? - Patacorow - 10-15-2010

sleep() is generally used to make the application go to "sleep", meaning, freezing it for a given amount of time (useful for game over screens or save & loads)

Therefore, imo, it's kinda confusing. But I should stop whining and praise the fact you're a one man team. Big Grin


RE: Are scripts functioning yet? - Jacob__mybb_import1 - 10-15-2010

(10-15-2010, 05:04 AM)Patacorow Wrote: sleep() is generally used to make the application go to "sleep", meaning, freezing it for a given amount of time (useful for game over screens or save & loads)

Therefore, imo, it's kinda confusing. But I should stop whining and praise the fact you're a one man team. Big Grin

In Java sleep(time) means to wait a certain number of seconds, wait() means the current thread should wait until another thread notifies it to do something.

Seems kind of backwards to me, but that's how it is...